mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-06 20:39:08 +00:00
FIX: map request body to the form wordpress
This commit is contained in:
@@ -6,8 +6,8 @@ import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filt
|
||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||
import { UsersService } from '../users/users.service';
|
||||
import { Language } from 'src/decorators/language.decorator';
|
||||
import { CreateUserOpenDataDTO } from './dto/create-user';
|
||||
import { OpenDataService } from './open-data.service';
|
||||
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
||||
|
||||
@Controller('open-data')
|
||||
@ApiInternalOnlyController()
|
||||
@@ -28,20 +28,45 @@ export class OpenDataController {
|
||||
@Post("/sharing-ocean-data")
|
||||
@ApiCreatedResponse()
|
||||
async createUser(
|
||||
@Body() body: CreateUserOpenDataDTO
|
||||
@Body()
|
||||
body: WordpressForm
|
||||
) {
|
||||
this.logger.info('createUser for open data' + JSON.stringify({ body }));
|
||||
|
||||
const OPENDATA_PUBLIC_USERS_GROUP_ID = "401573bb-334f-44b2-b30e-88d4cea31ae9";
|
||||
const OPENDATA_CUSTOMER_ID = "f239718a-a271-4ef9-ae7e-02a2f0f3aa6e";
|
||||
const roles = [OPENDATA_PUBLIC_USERS_GROUP_ID];
|
||||
|
||||
this.logger.info('createUser for open data' + JSON.stringify({ body }));
|
||||
const data = {}
|
||||
|
||||
try {
|
||||
await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, body, roles);
|
||||
Object.keys(body.fields)
|
||||
.filter(key => body.fields[key].required === "1")
|
||||
.forEach(key => {
|
||||
const field = body.fields[key]
|
||||
data[field.id] = field.value
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error('user data' + e.message);
|
||||
}
|
||||
|
||||
|
||||
const user: CreateUserOpenDataDTO = {
|
||||
email: data["email"],
|
||||
enquiryType: data["enquiry_type"],
|
||||
firstName: data["first_name"],
|
||||
lastName: data["last_name"],
|
||||
organization: data["organization"]
|
||||
}
|
||||
this.logger.info('user data' + JSON.stringify({ user }));
|
||||
|
||||
try {
|
||||
await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles);
|
||||
return "success"
|
||||
} catch (e) {
|
||||
this.logger.error('user data' + e.message);
|
||||
return e;
|
||||
}
|
||||
// return ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user