Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(endorsement-system): Store ownername #17248

Merged
merged 11 commits into from
Dec 17, 2024
Original file line number Diff line number Diff line change
@@ -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')
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ''
}
}
}
Loading