diff --git a/backend/services/src/setup/handler.ts b/backend/services/src/setup/handler.ts index fb2193ae5..0db3ecafa 100644 --- a/backend/services/src/setup/handler.ts +++ b/backend/services/src/setup/handler.ts @@ -76,6 +76,7 @@ export const handler: Handler = async (event) => { : fields[5] == "Manager" ? Role.Manager : Role.ViewOnly; + const txId = fields[4] !== "Ministry" ? fields[3] : ''; console.log('Inserting user', fields[0], cr, fields[3], @@ -86,7 +87,7 @@ export const handler: Handler = async (event) => { await userService.createUserWithPassword( fields[0], cr, - fields[3], + txId, fields[6], fields[1], ur, @@ -137,7 +138,7 @@ export const handler: Handler = async (event) => { try { const org = await companyService.create({ - taxId: fields[3], + taxId: fields[4] !== "Ministry" ? fields[3] : undefined, companyId: undefined, name: fields[0], email: fields[1], diff --git a/backend/services/src/shared/company/company.service.ts b/backend/services/src/shared/company/company.service.ts index c9ad507b6..21a0a9fbe 100644 --- a/backend/services/src/shared/company/company.service.ts +++ b/backend/services/src/shared/company/company.service.ts @@ -312,6 +312,16 @@ export class CompanyService { return companies && companies.length > 0 ? companies[0] : undefined; } + async findMinByCountry(countryCode: string): Promise { + const companies = await this.companyRepo.find({ + where: { + country: countryCode, + companyRole: CompanyRole.MINISTRY, + }, + }); + return companies && companies.length > 0 ? companies[0] : undefined; + } + async create(companyDto: OrganisationDto): Promise { this.logger.verbose("Company create received", companyDto.email); diff --git a/backend/services/src/shared/user/user.service.ts b/backend/services/src/shared/user/user.service.ts index 096e86c32..6f8cdd7a3 100644 --- a/backend/services/src/shared/user/user.service.ts +++ b/backend/services/src/shared/user/user.service.ts @@ -346,8 +346,8 @@ export class UserService { apiKey: string ) { let company: Company; - if (companyRole != CompanyRole.GOVERNMENT) { - if (!taxId) { + if (companyRole != CompanyRole.GOVERNMENT && companyRole !== CompanyRole.MINISTRY) { + if (!taxId || taxId === '') { throw new HttpException( "Tax id cannot be empty:" + email, HttpStatus.BAD_REQUEST @@ -355,7 +355,11 @@ export class UserService { } company = await this.companyService.findByTaxId(taxId); } else { - company = await this.companyService.findGovByCountry(this.configService.get("systemCountry")) + if(companyRole === CompanyRole.GOVERNMENT) { + company = await this.companyService.findGovByCountry(this.configService.get("systemCountry")) + } else if(companyRole === CompanyRole.MINISTRY) { + company = await this.companyService.findMinByCountry(this.configService.get("systemCountry")) + } } if (!company) { diff --git a/organisations.csv b/organisations.csv index 8c7194eef..deabf1cb5 100644 --- a/organisations.csv +++ b/organisations.csv @@ -1,7 +1,8 @@ -NAME,EMAIL,PHONE,ORGANISATION TAX ID,ORGANISATION TYPE(Developer|Certifier|API) +NAME,EMAIL,PHONE,ORGANISATION TAX ID,ORGANISATION TYPE(Developer|Certifier|API), SECTORAL SCOPE, MINISTER NAME Org 2,palinda+org2@xeptagon.com,,33333,Develop Org 3,palinda+org3@xeptagon.com,,55555,Develop Org 3,palinda+org3@xeptagon.com,,88888,Develop Cert 2,palinda+cert2@xeptagon.com,,44444,Certifier API,palinda+api@xeptagon.com,,66666,API -Org 4,palinda+org4@xeptagon.com,,77777,Develop \ No newline at end of file +Org 4,palinda+org4@xeptagon.com,,77777,Develop +Org Min,min+org4@xeptagon.com,,,Ministry,OrgMin,2-4 \ No newline at end of file diff --git a/users.csv b/users.csv index d6cf058ac..7de934390 100644 --- a/users.csv +++ b/users.csv @@ -1,7 +1,8 @@ -NAME,EMAIL,PHONE,ORGANISATION TAX ID,ORGANISATION TYPE(Government|Developer|Certifier|API),ROLE(admin|Manager|View),Password,APIKey +NAME,EMAIL,PHONE,ORGANISATION TAX ID | COMPANY ID,ORGANISATION TYPE(Government|Developer|Certifier|API),ROLE(admin|Manager|View),Password,APIKey Test User,palinda+add@xeptagon.com,,Government of Antarctica,Government,admin,123, Test Dev,palinda+dev@xeptagon.com,,33333,Developer,admin,123, Test Dev 2,palinda+dev2@xeptagon.com,,55555,Developer,admin,123, Test Dev 3,palinda+dev3@xeptagon.com,,88888,Developer,admin,123, Test Cert,palinda+cet@xeptagon.com,,44444,Certifier,admin,123, -Test API,palinda+api@xeptagon.com,,66666,API,admin,123,cGFsaW5kYSthcGlAeGVwdGFnb24uY29tX19fMTIzNDU= \ No newline at end of file +Test API,palinda+api@xeptagon.com,,66666,API,admin,123,cGFsaW5kYSthcGlAeGVwdGFnb24uY29tX19fMTIzNDU= +Test Min,min+admin@xeptagon.com,,,Ministry,admin,123, \ No newline at end of file