Skip to content

Commit

Permalink
AB#2826 hotfix: initial seed Kenya
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisvisser committed Aug 4, 2020
1 parent 997436b commit f7bbf56
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 1 deletion.
116 changes: 116 additions & 0 deletions services/121-service/examples/program-pilot-ken.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
5 changes: 4 additions & 1 deletion services/121-service/src/scripts/scripts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions services/121-service/src/scripts/scripts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -29,6 +30,7 @@ import { SeedPublish } from './seed-publish';
SeedSingleProgram,
SeedMultiProgram,
SeedPilotNLProgram,
SeedPilotKenProgram,
SeedDemoProgram,
],
controllers: [ScriptsController],
Expand Down
54 changes: 54 additions & 0 deletions services/121-service/src/scripts/seed-program-pilot-ken.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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;

0 comments on commit f7bbf56

Please sign in to comment.