@@ -194,6 +194,25 @@ export class OrganizationService {
194
194
}
195
195
}
196
196
197
+ private async ensureOrganizationExists ( orgId : string ) : Promise < void > {
198
+ const organizationExist = await this . organizationRepository . getOrgProfile ( orgId ) ;
199
+ if ( ! organizationExist ) {
200
+ throw new NotFoundException ( ResponseMessages . organisation . error . notFound ) ;
201
+ }
202
+ }
203
+ private async ensureNotExistingPrimaryDid ( orgId : string , did : string ) : Promise < void > {
204
+ const orgAgentDetails = await this . organizationRepository . getAgentEndPoint ( orgId ) ;
205
+ if ( orgAgentDetails . orgDid === did ) {
206
+ throw new ConflictException ( ResponseMessages . organisation . error . primaryDid ) ;
207
+ }
208
+ }
209
+ private async ensureDidBelongsToOrg ( orgId : string , did : string ) : Promise < void > {
210
+ const organizationDidList = await this . organizationRepository . getAllOrganizationDid ( orgId ) ;
211
+ const isDidMatch = organizationDidList . some ( ( item ) => item . did === did ) ;
212
+ if ( ! isDidMatch ) {
213
+ throw new NotFoundException ( ResponseMessages . organisation . error . didNotFound ) ;
214
+ }
215
+ }
197
216
/**
198
217
*
199
218
* @param registerOrgDto
@@ -203,22 +222,11 @@ export class OrganizationService {
203
222
// eslint-disable-next-line camelcase
204
223
async setPrimaryDid ( orgId : string , did : string , id : string ) : Promise < string > {
205
224
try {
206
- const organizationExist = await this . organizationRepository . getOrgProfile ( orgId ) ;
207
- if ( ! organizationExist ) {
208
- throw new NotFoundException ( ResponseMessages . organisation . error . notFound ) ;
209
- }
210
- const orgAgentDetails = await this . organizationRepository . getAgentEndPoint ( orgId ) ;
211
- if ( orgAgentDetails . orgDid === did ) {
212
- throw new ConflictException ( ResponseMessages . organisation . error . primaryDid ) ;
213
- }
225
+ await this . ensureOrganizationExists ( orgId ) ;
226
+ await this . ensureNotExistingPrimaryDid ( orgId , did ) ;
214
227
215
228
//check user DID exist in the organization's did list
216
- const organizationDidList = await this . organizationRepository . getAllOrganizationDid ( orgId ) ;
217
- const isDidMatch = organizationDidList . some ( ( item ) => item . did === did ) ;
218
-
219
- if ( ! isDidMatch ) {
220
- throw new NotFoundException ( ResponseMessages . organisation . error . didNotFound ) ;
221
- }
229
+ await this . ensureDidBelongsToOrg ( orgId , did ) ;
222
230
const didDetails = await this . organizationRepository . getDidDetailsByDid ( did ) ;
223
231
224
232
if ( ! didDetails ) {
@@ -1735,7 +1743,7 @@ export class OrganizationService {
1735
1743
emailData . emailTo = email ;
1736
1744
emailData . emailSubject = `Removal of participation of “${ orgName } ”` ;
1737
1745
1738
- emailData . emailHtml = await urlEmailTemplate . sendDeleteOrgMemberEmailTemplate ( email , orgName , orgRole ) ;
1746
+ emailData . emailHtml = urlEmailTemplate . sendDeleteOrgMemberEmailTemplate ( email , orgName , orgRole ) ;
1739
1747
1740
1748
//Email is sent to user for the verification through emailData
1741
1749
const isEmailSent = await sendEmail ( emailData ) ;
0 commit comments