diff --git a/docsfera.json b/docsfera.json index 801658d..0acfbbe 100644 --- a/docsfera.json +++ b/docsfera.json @@ -10100,6 +10100,21 @@ "entities" ] }, + "Column": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "name", + "type" + ] + }, "TableColumns": { "type": "object", "properties": { @@ -10115,17 +10130,25 @@ "references": { "type": "array", "items": { - "type": "string" + "$ref": "#/components/schemas/Column" } }, "type": { "type": "string" + }, + "identifier_columns": { + "type": "array", + "items": { + "type": "string" + } + }, + "reference_column": { + "$ref": "#/components/schemas/Column" } }, "required": [ "name", "columns", - "references", "type" ] }, @@ -11005,7 +11028,7 @@ "enabled" ] }, - "CustomerLink": { + "CustomerLinkItem": { "type": "object", "properties": { "href": { @@ -11027,28 +11050,101 @@ "description" ] }, - "CustomerLinksResponse": { + "CustomerSidebarLinkItem": { "type": "object", "properties": { - "links": { + "type": { + "type": "string" + }, + "title": { + "type": "string" + }, + "link": { + "type": "string" + }, + "icon": { + "type": "string" + } + }, + "required": [ + "type", + "title", + "link" + ] + }, + "CustomerSidebarMenuItem": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "title": { + "type": "string" + }, + "icon": { + "type": "string" + }, + "items": { "type": "array", "items": { - "$ref": "#/components/schemas/CustomerLink" + "$ref": "#/components/schemas/CustomerSidebarLinkItem" } } }, "required": [ - "links" + "type", + "title", + "items" ] }, + "CustomerSidebarSection": { + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CustomerSidebarMenuItem" + } + } + }, + "required": [ + "title", + "items" + ] + }, + "CustomerLinksConfig": { + "type": "object", + "properties": { + "home": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CustomerLinkItem" + } + }, + "sidebar": { + "type": "array", + "items": { + "$ref": "#/components/schemas/CustomerSidebarSection" + } + } + } + }, + "CustomerLinksResponse": { + "type": "object", + "properties": { + "links": { + "$ref": "#/components/schemas/CustomerLinksConfig" + } + } + }, "CustomerLinkRequest": { "type": "object", "properties": { "links": { - "type": "array", - "items": { - "$ref": "#/components/schemas/CustomerLink" - } + "$ref": "#/components/schemas/CustomerLinksConfig" } }, "required": [ diff --git a/package-lock.json b/package-lock.json index 4d90eb7..615ef97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@aws-sdk/signature-v4": "^3.370.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "^3.38.0-beta.26", + "@dadosfera/protospack-v2": "^3.38.0-beta.29", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", @@ -1744,9 +1744,9 @@ } }, "node_modules/@dadosfera/protospack-v2": { - "version": "3.38.0-beta.26", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.38.0-beta.26.tgz", - "integrity": "sha512-N8NS7+djLGy0wJXk00+4oupqd/wBIQ1f+YBBhK2y9x4guFXYK1KWIrPZhPj+gaU8g2KNkqKoT7SnE9PXNxlLSQ==", + "version": "3.38.0-beta.29", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.38.0-beta.29.tgz", + "integrity": "sha512-1TUHKoSi2h/Pt+YEno9KOj8Zv2uAjT4qPS3xK26Tk2Wxg/OTlbxevPc+iwy8EI6YsT24WsbZfkb5JfKRlvKFHA==", "dependencies": { "@grpc/grpc-js": "^1.9.3", "rxjs": "^7.5.5" diff --git a/package.json b/package.json index 4fd10bd..9a13d42 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@aws-sdk/signature-v4": "^3.370.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "^3.38.0-beta.26", + "@dadosfera/protospack-v2": "^3.38.0-beta.29", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", diff --git a/src/modules/customers/customers.service.ts b/src/modules/customers/customers.service.ts index 602943b..bcbd11d 100644 --- a/src/modules/customers/customers.service.ts +++ b/src/modules/customers/customers.service.ts @@ -9,12 +9,12 @@ import { } from '@nestjs/common'; import { firstValueFrom, lastValueFrom } from 'rxjs'; -import { Link } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities'; import { DucClient } from '../duc/client.config'; import { ClientGrpc } from '@nestjs/microservices'; import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc'; -import { CustomerUpdateRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages'; +import { CustomerSetLinksRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages'; import { CustomersProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service'; +import { CustomerLinksConfig } from './dtos/customers'; import ErrorCodes from 'src/utils/errorCodes'; import jwt from 'jsonwebtoken'; import { @@ -67,12 +67,12 @@ export class CustomersService implements OnModuleInit { ) } - async getLinks(customerId: string) { + async getLinks(customerId: string): Promise { try { const result = await lastValueFrom( - this.customerService.CustomerFindOneById({ id: customerId }), + this.customerService.CustomerGetLinks({ id: customerId }), ); - return result.customer?.links || []; + return (result.links as unknown as CustomerLinksConfig) || null; } catch (err) { if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) throw new HttpException(err.details, HttpStatus.NOT_FOUND); @@ -80,17 +80,17 @@ export class CustomersService implements OnModuleInit { } } - async setLinks(customerId: string, links: Link[]) { + async setLinks(customerId: string, links: CustomerLinksConfig) { if (!customerId || !links) { throw new HttpException(null, HttpStatus.BAD_REQUEST); } try { return await firstValueFrom( - this.customerService.CustomerUpdate({ + this.customerService.CustomerSetLinks({ id: customerId, - links, - } as CustomerUpdateRequest), + links: links as unknown as CustomerSetLinksRequest['links'], + }), ); } catch (err) { if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) diff --git a/src/modules/customers/dtos/customers.ts b/src/modules/customers/dtos/customers.ts index db56ee3..7299b23 100644 --- a/src/modules/customers/dtos/customers.ts +++ b/src/modules/customers/dtos/customers.ts @@ -1,7 +1,6 @@ -import { Link } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -export class CustomerLink implements Link { +export class CustomerLinkItem { @ApiProperty() href: string; @ApiProperty() @@ -9,15 +8,51 @@ export class CustomerLink implements Link { @ApiProperty() description: string; @ApiPropertyOptional() - iconSrc: string; + iconSrc?: string; } + +export class CustomerSidebarLinkItem { + @ApiProperty() + type: 'link'; + @ApiProperty() + title: string; + @ApiProperty() + link: string; + @ApiPropertyOptional() + icon?: string; +} + +export class CustomerSidebarMenuItem { + @ApiProperty() + type: 'menu'; + @ApiProperty() + title: string; + @ApiPropertyOptional() + icon?: string; + @ApiProperty({ type: [CustomerSidebarLinkItem] }) + items: CustomerSidebarLinkItem[]; +} + +export class CustomerSidebarSection { + @ApiProperty() + title: string; + @ApiProperty({ type: [CustomerSidebarMenuItem] }) + items: CustomerSidebarMenuItem[]; +} + +export class CustomerLinksConfig { + @ApiPropertyOptional({ type: [CustomerLinkItem] }) + home?: CustomerLinkItem[]; + @ApiPropertyOptional({ type: [CustomerSidebarSection] }) + sidebar?: CustomerSidebarSection[]; +} + export class CustomerLinkRequest { - @ApiProperty({ type: [CustomerLink] }) - links: CustomerLink[]; + @ApiProperty({ type: CustomerLinksConfig }) + links: CustomerLinksConfig; } export class CustomerLinksResponse { - @ApiProperty({ type: [CustomerLink] }) - links: CustomerLink[]; -} - + @ApiPropertyOptional({ type: CustomerLinksConfig }) + links?: CustomerLinksConfig; +} \ No newline at end of file diff --git a/src/modules/inputs/dtos/input.model.ts b/src/modules/inputs/dtos/input.model.ts index 7b40d1e..ef558be 100644 --- a/src/modules/inputs/dtos/input.model.ts +++ b/src/modules/inputs/dtos/input.model.ts @@ -11,10 +11,14 @@ export class TableColumns { name: string; @ApiProperty() columns: string[]; - @ApiProperty() + @ApiPropertyOptional({ type: [Column] }) references: Column[]; @ApiProperty() type: string; + @ApiPropertyOptional({ type: [String] }) + identifier_columns?: string[]; + @ApiPropertyOptional({ type: Column }) + reference_column?: Column; } export class AvailableEntity { @ApiProperty() diff --git a/src/modules/inputs/inputs.service.ts b/src/modules/inputs/inputs.service.ts index 94dd27a..d258215 100644 --- a/src/modules/inputs/inputs.service.ts +++ b/src/modules/inputs/inputs.service.ts @@ -164,6 +164,11 @@ export class InputsService { const inputCreateGenericRequest: InputCreateGenericRequest = { input: { ...body, + tables: (body.tables || []).map((table) => ({ + ...table, + identifier_columns: table.identifier_columns || [], + reference_column: table.reference_column || table.references?.[0], + })), }, info, };