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..7afadcf304a4 --- /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('endorsement_list', 'owner_name', { + type: Sequelize.STRING, + allowNull: true, + }) + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.removeColumn('endorsement_list', 'owner_name') + }, +} 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..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 @@ -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) @@ -305,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 { @@ -953,4 +961,19 @@ export class EndorsementListService { ) } } + + private async fetchOwnerNameFromRegistry( + nationalId: string, + ): Promise<string> { + 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 '' + } + } }