Skip to content

Commit

Permalink
fixed the ministry user creation from csv files
Browse files Browse the repository at this point in the history
  • Loading branch information
YathurshanT committed Aug 14, 2023
1 parent edbcab9 commit 041d574
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
5 changes: 3 additions & 2 deletions backend/services/src/setup/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -86,7 +87,7 @@ export const handler: Handler = async (event) => {
await userService.createUserWithPassword(
fields[0],
cr,
fields[3],
txId,
fields[6],
fields[1],
ur,
Expand Down Expand Up @@ -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],
Expand Down
10 changes: 10 additions & 0 deletions backend/services/src/shared/company/company.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ export class CompanyService {
return companies && companies.length > 0 ? companies[0] : undefined;
}

async findMinByCountry(countryCode: string): Promise<Company | undefined> {
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<Company | undefined> {
this.logger.verbose("Company create received", companyDto.email);

Expand Down
10 changes: 7 additions & 3 deletions backend/services/src/shared/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,20 @@ 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
);
}
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) {
Expand Down
5 changes: 3 additions & 2 deletions organisations.csv
Original file line number Diff line number Diff line change
@@ -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,[email protected],,33333,Develop
Org 3,[email protected],,55555,Develop
Org 3,[email protected],,88888,Develop
Cert 2,[email protected],,44444,Certifier
API,[email protected],,66666,API
Org 4,[email protected],,77777,Develop
Org 4,[email protected],,77777,Develop
Org Min,[email protected],,,Ministry,OrgMin,2-4
5 changes: 3 additions & 2 deletions users.csv
Original file line number Diff line number Diff line change
@@ -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,[email protected],,Government of Antarctica,Government,admin,123,
Test Dev,[email protected],,33333,Developer,admin,123,
Test Dev 2,[email protected],,55555,Developer,admin,123,
Test Dev 3,[email protected],,88888,Developer,admin,123,
Test Cert,[email protected],,44444,Certifier,admin,123,
Test API,[email protected],,66666,API,admin,123,cGFsaW5kYSthcGlAeGVwdGFnb24uY29tX19fMTIzNDU=
Test API,[email protected],,66666,API,admin,123,cGFsaW5kYSthcGlAeGVwdGFnb24uY29tX19fMTIzNDU=
Test Min,[email protected],,,Ministry,admin,123,

0 comments on commit 041d574

Please sign in to comment.