From 26c89b56d0611b4669668606e44ff1236924ce84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafn=20=C3=81rnason?= Date: Mon, 16 Dec 2024 11:52:22 +0000 Subject: [PATCH 1/8] ownername db and logic --- .../20241216113500-add-ownerName-column.js | 12 ++++++++++++ .../endorsementList/endorsementList.model.ts | 7 +++++++ .../endorsementList.service.ts | 19 ++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js diff --git a/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js new file mode 100644 index 000000000000..ecdb2025baeb --- /dev/null +++ b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js @@ -0,0 +1,12 @@ +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.addColumn('Endorsements', 'ownerName', { + type: Sequelize.STRING, + allowNull: true, + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.removeColumn('Endorsements', 'ownerName'); + }, +}; diff --git a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.model.ts b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.model.ts index 82b4c591cea8..8f00e8d7ee57 100644 --- a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.model.ts +++ b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.model.ts @@ -85,6 +85,13 @@ export class EndorsementList extends Model { }) owner!: string + @ApiProperty() + @Column({ + type: DataType.STRING, + allowNull: true, + }) + ownerName?: string + @ApiProperty() @Column({ type: DataType.BOOLEAN, diff --git a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts index 3624f7b1b88f..79953fe26252 100644 --- a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts +++ b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts @@ -247,7 +247,11 @@ export class EndorsementListService { ]) } this.logger.info(`Creating endorsement list: ${list.title}`) - const endorsementList = await this.endorsementListModel.create({ ...list }) + const ownerName = await this.fetchOwnerNameFromRegistry(list.owner); + const endorsementList = await this.endorsementListModel.create({ + ...list, + ownerName, + }) if (process.env.NODE_ENV === 'production') { await this.emailCreated(endorsementList) @@ -953,4 +957,17 @@ export class EndorsementListService { ) } } + + private async fetchOwnerNameFromRegistry(nationalId: string): Promise { + try { + const person = await this.nationalRegistryApiV3.getName(nationalId) + return person?.fulltNafn ? person.fulltNafn : '' + } catch (error) { + this.logger.error('Failed to fetch owner name from NationalRegistry', { + error: error.message, + nationalId, + }) + return '' + } + } } From 38d156ca94fe1b94546954f237247a0fdca9ef64 Mon Sep 17 00:00:00 2001 From: andes-it Date: Mon, 16 Dec 2024 12:12:56 +0000 Subject: [PATCH 2/8] chore: nx format:write update dirty files --- .../api/migrations/20241216113500-add-ownerName-column.js | 6 +++--- .../app/modules/endorsementList/endorsementList.service.ts | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js index ecdb2025baeb..422e33d75850 100644 --- a/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js +++ b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js @@ -3,10 +3,10 @@ module.exports = { await queryInterface.addColumn('Endorsements', 'ownerName', { type: Sequelize.STRING, allowNull: true, - }); + }) }, down: async (queryInterface, Sequelize) => { - await queryInterface.removeColumn('Endorsements', 'ownerName'); + await queryInterface.removeColumn('Endorsements', 'ownerName') }, -}; +} diff --git a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts index 79953fe26252..e1a2674be015 100644 --- a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts +++ b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts @@ -247,7 +247,7 @@ export class EndorsementListService { ]) } this.logger.info(`Creating endorsement list: ${list.title}`) - const ownerName = await this.fetchOwnerNameFromRegistry(list.owner); + const ownerName = await this.fetchOwnerNameFromRegistry(list.owner) const endorsementList = await this.endorsementListModel.create({ ...list, ownerName, @@ -958,7 +958,9 @@ export class EndorsementListService { } } - private async fetchOwnerNameFromRegistry(nationalId: string): Promise { + private async fetchOwnerNameFromRegistry( + nationalId: string, + ): Promise { try { const person = await this.nationalRegistryApiV3.getName(nationalId) return person?.fulltNafn ? person.fulltNafn : '' From ccaf6d7f34ac59425b271b5cc88bce547c1664a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafn=20=C3=81rnason?= Date: Mon, 16 Dec 2024 12:45:20 +0000 Subject: [PATCH 3/8] tweaks --- .../api/migrations/20241216113500-add-ownerName-column.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js index ecdb2025baeb..3aca1ae3887c 100644 --- a/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js +++ b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js @@ -1,12 +1,12 @@ module.exports = { up: async (queryInterface, Sequelize) => { - await queryInterface.addColumn('Endorsements', 'ownerName', { + await queryInterface.addColumn('endorsement_list', 'owner_name', { type: Sequelize.STRING, allowNull: true, }); }, down: async (queryInterface, Sequelize) => { - await queryInterface.removeColumn('Endorsements', 'ownerName'); + await queryInterface.removeColumn('endorsement_list', 'owner_name'); }, }; From 52d4d1afcf23e642b0aa378a47000d33539a30f9 Mon Sep 17 00:00:00 2001 From: andes-it Date: Mon, 16 Dec 2024 13:05:01 +0000 Subject: [PATCH 4/8] chore: nx format:write update dirty files --- .../api/migrations/20241216113500-add-ownerName-column.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js index 7931361d50fd..7afadcf304a4 100644 --- a/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js +++ b/apps/services/endorsements/api/migrations/20241216113500-add-ownerName-column.js @@ -7,6 +7,6 @@ module.exports = { }, down: async (queryInterface, Sequelize) => { - await queryInterface.removeColumn('endorsement_list', 'owner_name'); + await queryInterface.removeColumn('endorsement_list', 'owner_name') }, } From 5d6af5bcb5d5339a6e5a2d28b9b4b568e90e52bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafn=20=C3=81rnason?= Date: Mon, 16 Dec 2024 14:14:42 +0000 Subject: [PATCH 5/8] Empty commit for triggering CI/CD From d66a77c094a4f498cfad70fd10061c8a8e228496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafn=20=C3=81rnason?= Date: Mon, 16 Dec 2024 14:51:21 +0000 Subject: [PATCH 6/8] db check fallback --- .../app/modules/endorsementList/endorsementList.service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts index e1a2674be015..5f5b4bb71cb6 100644 --- a/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts +++ b/apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts @@ -309,6 +309,10 @@ export class EndorsementListService { throw new NotFoundException(['This endorsement list does not exist.']) } owner = endorsementList.owner + // Use stored ownerName if available + if (endorsementList.ownerName) { + return endorsementList.ownerName + } } try { From b811b19ea417d445bd0b380975ea7ddb6a12974d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafn=20=C3=81rnason?= Date: Mon, 16 Dec 2024 15:32:42 +0000 Subject: [PATCH 7/8] Empty commit for triggering CI/CD From 89df8367d6493c6e23a69da868428cdd4a031eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafn=20=C3=81rnason?= Date: Mon, 16 Dec 2024 15:34:28 +0000 Subject: [PATCH 8/8] Empty commit for triggering CI/CD