From f7bbf56a7f1ae2d6bd5d4567e7bec55b07cbfca0 Mon Sep 17 00:00:00 2001 From: Jannis Visser Date: Tue, 4 Aug 2020 16:09:27 +0200 Subject: [PATCH] AB#2826 hotfix: initial seed Kenya --- .../examples/program-pilot-ken.json | 116 ++++++++++++++++++ .../src/scripts/scripts.controller.ts | 5 +- .../121-service/src/scripts/scripts.module.ts | 2 + .../src/scripts/seed-program-pilot-ken.ts | 54 ++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 services/121-service/examples/program-pilot-ken.json create mode 100644 services/121-service/src/scripts/seed-program-pilot-ken.ts diff --git a/services/121-service/examples/program-pilot-ken.json b/services/121-service/examples/program-pilot-ken.json new file mode 100644 index 0000000000..18afb8bed5 --- /dev/null +++ b/services/121-service/examples/program-pilot-ken.json @@ -0,0 +1,116 @@ +{ + "published": false, + "state": "design", + "location": "Kenya", + "ngo": "KRCS", + "countryId": 1, + "title": { + "en": "Pilot - Kenya" + }, + "description": { + "en": "Program description" + }, + "descLocation": { + "en": "Location such and such." + }, + "descHumanitarianObjective": { + "en": "Humanitarian objective of program is such and such." + }, + "descCashType": { + "en": "Unconditional multi-purpose" + }, + "startDate": "2020-01-01T12:00:00Z", + "endDate": "2020-12-31T12:00:00Z", + "currency": "KES", + "distributionFrequency": "month", + "distributionDuration": 3, + "fixedTransferValue": 35, + "financialServiceProviders": [ + { + "id": 1 + }, + { + "id": 2 + } + ], + "inclusionCalculationType": "highestScoresX", + "minimumScore": 0, + "highestScoresX": 250, + "meetingDocuments": { + "en": "Document 1; Document 2; Document 3" + }, + "notifications": { + "en": { + "included": "You have been included in this program.", + "rejected": "Unfortunately we have to inform you that you will not receive any (more) payments for this program. If you have questions, please contact us." + } + }, + "customCriteria": [ + { + "criterium": "name", + "label": { + "en": "My full name:" + }, + "answerType": "text", + "criteriumType": "standard", + "options": null, + "persistence": true, + "scoring": {} + }, + { + "criterium": "dob", + "label": { + "en": "My date of birth:" + }, + "answerType": "date", + "criteriumType": "standard", + "options": null, + "persistence": true, + "scoring": {} + }, + { + "criterium": "phoneNumber", + "label": { + "en": "My phonenumber:" + }, + "answerType": "tel", + "criteriumType": "standard", + "options": null, + "persistence": true, + "scoring": {} + }, + { + "criterium": "sample", + "label": { + "en": "1. Sample vulnerability question:" + }, + "answerType": "dropdown", + "criteriumType": "standard", + "options": [ + { + "option": "optionA", + "label": { + "en": "Option A" + } + }, + { + "option": "optionB", + "label": { + "en": "Option B" + } + }, + { + "option": "optionC", + "label": { + "en": "Option C" + } + } + ], + "scoring": { + "optionA": 3, + "optionB": 6, + "optionC": 9 + } + } + ] +} diff --git a/services/121-service/src/scripts/scripts.controller.ts b/services/121-service/src/scripts/scripts.controller.ts index 6e667bacb9..a63777c904 100644 --- a/services/121-service/src/scripts/scripts.controller.ts +++ b/services/121-service/src/scripts/scripts.controller.ts @@ -5,13 +5,14 @@ import { Connection } from 'typeorm'; import { SeedSingleProgram } from './seed-program-single'; import { SeedDemoProgram } from './seed-program-demo'; import { SeedPilotNLProgram } from './seed-program-pilot-nl'; +import { SeedPilotKenProgram } from './seed-program-pilot-ken'; class ResetDto { @ApiModelProperty({ example: 'fill_in_secret' }) @IsNotEmpty() @IsString() public readonly secret: string; - @ApiModelProperty({ example: 'demo / pilot-nl / single' }) + @ApiModelProperty({ example: 'pilot-nl / pilot-ken / demo / single' }) public readonly script: string; } @@ -30,6 +31,8 @@ export class ScriptsController { seed = new SeedDemoProgram(this.connection); } else if (body.script == 'pilot-nl') { seed = new SeedPilotNLProgram(this.connection); + } else if (body.script == 'pilot-ken') { + seed = new SeedPilotKenProgram(this.connection); } else { seed = new SeedSingleProgram(this.connection); } diff --git a/services/121-service/src/scripts/scripts.module.ts b/services/121-service/src/scripts/scripts.module.ts index 2d0122b5ad..d05f082da2 100644 --- a/services/121-service/src/scripts/scripts.module.ts +++ b/services/121-service/src/scripts/scripts.module.ts @@ -10,6 +10,7 @@ import { SeedHelper } from './seed-helper'; import { SeedMultiProgram } from './seed-program-multi'; import { SeedSingleProgram } from './seed-program-single'; import { SeedPilotNLProgram } from './seed-program-pilot-nl'; +import { SeedPilotKenProgram } from './seed-program-pilot-ken'; import { SeedDemoProgram } from './seed-program-demo'; import { SeedPublish } from './seed-publish'; @@ -29,6 +30,7 @@ import { SeedPublish } from './seed-publish'; SeedSingleProgram, SeedMultiProgram, SeedPilotNLProgram, + SeedPilotKenProgram, SeedDemoProgram, ], controllers: [ScriptsController], diff --git a/services/121-service/src/scripts/seed-program-pilot-ken.ts b/services/121-service/src/scripts/seed-program-pilot-ken.ts new file mode 100644 index 0000000000..537def3330 --- /dev/null +++ b/services/121-service/src/scripts/seed-program-pilot-ken.ts @@ -0,0 +1,54 @@ +import { Injectable } from '@nestjs/common'; +import { InterfaceScript } from './scripts.module'; +import { Connection } from 'typeorm'; + +import { SeedHelper } from './seed-helper'; +import { SeedInit } from './seed-init'; + +import { CountryEntity } from '../programs/country/country.entity'; +import fspBank from '../../examples/fsp-bank.json'; +import fspMobileMoney from '../../examples/fsp-mobile-money.json'; +import programPilotKen from '../../examples/program-pilot-ken.json'; +import { USERCONFIG } from '../secrets'; +import { UserRole } from '../user-role.enum'; + +@Injectable() +export class SeedPilotKenProgram implements InterfaceScript { + public constructor(private connection: Connection) {} + + private readonly seedHelper = new SeedHelper(this.connection); + + public async run(): Promise { + const seedInit = await new SeedInit(this.connection); + await seedInit.run(); + + // ***** CREATE USERS ***** + await this.seedHelper.addUser({ + role: UserRole.ProjectOfficer, + email: USERCONFIG.emailProjectOfficer, + countryId: USERCONFIG.countryId, + password: USERCONFIG.passwordProjectOfficer, + }); + + await this.seedHelper.addUser({ + role: UserRole.ProgramManager, + email: USERCONFIG.emailProgramManager, + countryId: USERCONFIG.countryId, + password: USERCONFIG.passwordProgramManager, + }); + + // ***** CREATE COUNTRIES ***** + const countryRepository = this.connection.getRepository(CountryEntity); + await countryRepository.save([{ country: 'Kenya' }]); + + // ***** CREATE FINANCIAL SERVICE PROVIDERS ***** + await this.seedHelper.addFsp(fspBank); + await this.seedHelper.addFsp(fspMobileMoney); + + // ***** CREATE PROGRAM ***** + const examplePrograms = [programPilotKen]; + await this.seedHelper.addPrograms(examplePrograms, 1); + } +} + +export default SeedPilotKenProgram;