mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-30 02:29:09 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7aadf4d9d1 | ||
|
|
af8fa72377 | ||
|
|
c51f262474 | ||
|
|
54d19a78ab | ||
|
|
66f33a2246 | ||
|
|
55d9441d10 | ||
|
|
8b7342652e | ||
|
|
118c2653a5 | ||
|
|
f7d0128d99 | ||
|
|
12cc555491 |
@@ -1,5 +1,5 @@
|
||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||
import { Body, Controller, Inject, Post, UseFilters, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Header, HttpCode, Inject, Param, Post, Query, Req, UseFilters, UseGuards } from '@nestjs/common';
|
||||
import { ApiCreatedResponse, ApiHeaders, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||
@@ -9,6 +9,10 @@ import { Language } from 'src/decorators/language.decorator';
|
||||
import { OpenDataService } from './open-data.service';
|
||||
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
||||
import { CORSGuard, SetOrigin } from 'src/decorators/set-origin.decorator';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||
import { request } from 'http';
|
||||
import { Request } from 'express';
|
||||
|
||||
@Controller('open-data')
|
||||
@ApiInternalOnlyController()
|
||||
@@ -27,14 +31,25 @@ export class OpenDataController {
|
||||
}
|
||||
|
||||
@Post("/sharing-ocean-data")
|
||||
@SetOrigin('https://devsbm.dadosfera.io/')
|
||||
@UseGuards(CORSGuard)
|
||||
// @SetOrigin('devsbm.dadosfera.io')
|
||||
// @UseGuards(CORSGuard)
|
||||
@HttpCode(200)
|
||||
@Header('content-type', 'application/json')
|
||||
@ApiOkResponse()
|
||||
async createUser(
|
||||
@Body()
|
||||
body: WordpressForm
|
||||
body: WordpressForm,
|
||||
@Query('language')
|
||||
language: string,
|
||||
@Req()
|
||||
request: Request,
|
||||
) {
|
||||
this.logger.info('createUser for open data' + JSON.stringify({ body }));
|
||||
this.logger.info('createUser for open data'
|
||||
+ JSON.stringify({
|
||||
origin: request.headers.origin,
|
||||
language,
|
||||
body
|
||||
}));
|
||||
|
||||
// "401573bb-334f-44b2-b30e-88d4cea31ae9"
|
||||
// const OPENDATA_PUBLIC_USERS_GROUP_ID = process.env.OPEN_GROUP_ID;
|
||||
@@ -43,6 +58,9 @@ export class OpenDataController {
|
||||
const OPENDATA_CUSTOMER_ID = "bb4e9b26-d465-40ff-9345-e768ca69a55e";
|
||||
|
||||
const roles = ["4d621501-5ea4-444b-b46e-1a009f3132ff"];
|
||||
const metadata = PackTheMetadata({
|
||||
language: language || 'en-us'
|
||||
});
|
||||
|
||||
const data = {}
|
||||
|
||||
@@ -52,9 +70,9 @@ export class OpenDataController {
|
||||
.forEach(key => {
|
||||
const field = body.fields[key]
|
||||
data[field.id] = field.value
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error('user data' + e.message);
|
||||
this.logger.error('user data ' + e.message);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,13 +86,21 @@ export class OpenDataController {
|
||||
this.logger.info('user request' + JSON.stringify({ user, roles, customer: OPENDATA_CUSTOMER_ID }));
|
||||
|
||||
try {
|
||||
const response = await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles);
|
||||
this.logger.info('user created with sucessfull data' + JSON.stringify(response));
|
||||
return "success"
|
||||
await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles, metadata);
|
||||
this.logger.info('user created with sucessfull data');
|
||||
return {
|
||||
success: true,
|
||||
status: 'success',
|
||||
message: 'user created with succesfull'
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.error('user data' + e.message);
|
||||
return e;
|
||||
this.logger.error('failed with exception: ' + e.message);
|
||||
return {
|
||||
success: false,
|
||||
status: 'failed',
|
||||
message: e.message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { UsersProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfa
|
||||
import { DucClient } from '../duc/client.config';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
|
||||
@Injectable()
|
||||
export class OpenDataService implements OnModuleInit {
|
||||
@@ -28,7 +29,7 @@ export class OpenDataService implements OnModuleInit {
|
||||
|
||||
}
|
||||
|
||||
async createUser(customerId: string, data: CreateUserOpenDataDTO, roleIds: string[]) {
|
||||
async createUser(customerId: string, data: CreateUserOpenDataDTO, roleIds: string[], metadata: Metadata) {
|
||||
const body = {
|
||||
email: data.email,
|
||||
name: data.firstName + " " + data.lastName,
|
||||
@@ -40,7 +41,7 @@ export class OpenDataService implements OnModuleInit {
|
||||
|
||||
try {
|
||||
await lastValueFrom(
|
||||
this.usersClientService.SimpleUserCreate(body),
|
||||
this.usersClientService.SimpleUserCreate(body, metadata),
|
||||
);
|
||||
return "User created";
|
||||
} catch(err) {
|
||||
|
||||
Reference in New Issue
Block a user