Skip to content

Commit

Permalink
feat(endorsement-system): Store ownername (#17248)
Browse files Browse the repository at this point in the history
* ownername db and logic

* chore: nx format:write update dirty files

* tweaks

* chore: nx format:write update dirty files

* Empty commit for triggering CI/CD

* db check fallback

* Empty commit for triggering CI/CD

* Empty commit for triggering CI/CD

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 980afb0 commit b280879
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
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 ''
}
}
}

0 comments on commit b280879

Please sign in to comment.