Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] Chore update seed recommitment #480

Merged
merged 10 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ START_RECOMMITMENT_SCHEDULE=0 9 * * *
NOTIFICATION_SCHEDULE=0 * * * *
TEST_RUN=true
VIEWS=views/test
RECOMMITMENT_MINISTRY=
RECOMMITMENT_MINISTRY=
START_DATE=2025-01-20
END_DATE=2021-02-21
18 changes: 14 additions & 4 deletions .github/workflows/ci-personnel-faker-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: Seed dev faker data
environment: dev
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 45
env:
OS_NAMESPACE_SUFFIX: dev
AUTH_TOKEN: ${{ secrets.OC_AUTH_TOKEN }}
Expand All @@ -37,11 +37,21 @@ jobs:
wget https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/linux/oc.tar.gz
tar -xvf oc.tar.gz
sudo mv oc /usr/local/bin/
- name: Seed Data
- name: Seed Personnel Data
run: |
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
make seed-oc-personnel
make seed-oc-bcws
make seed-oc-emcr
- name: Seed BCWS Data
run: |
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
make seed-oc-bcws
- name: Seed EMCR Data
run: |
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
make seed-oc-emcr
16 changes: 14 additions & 2 deletions .github/workflows/ci-personnel-faker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,21 @@ jobs:
wget https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/linux/oc.tar.gz
tar -xvf oc.tar.gz
sudo mv oc /usr/local/bin/
- name: Seed Data
- name: Seed Personnel Data
run: |
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
make seed-oc-personnel
make seed-oc-personnel
- name: Seed BCWS Data
run: |
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
make seed-oc-bcws
- name: Seed EMCR Data
run: |
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
make seed-oc-emcr
4 changes: 4 additions & 0 deletions .github/workflows/ci-recommitment-faker-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ env:
TOOLS_TOKEN: ${{ secrets.OC_TOOLS_TOKEN }}
PROJECT: tcloud
ENV: dev
START_DATE: 2025-01-20
END_DATE: 2025-02-21

jobs:
seed_faker_data:
Expand Down Expand Up @@ -42,4 +44,6 @@ jobs:
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
export START_DATE=${{ env.START_DATE }}
export END_DATE=${{ env.END_DATE }}
make seed-oc-recommitment
4 changes: 4 additions & 0 deletions .github/workflows/ci-recommitment-faker-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ env:
TOOLS_TOKEN: ${{ secrets.OC_TOOLS_TOKEN }}
PROJECT: tcloud
ENV: test
START_DATE: 2025-01-20
END_DATE: 2025-02-21

jobs:
seed_faker_data:
Expand Down Expand Up @@ -42,4 +44,6 @@ jobs:
cd "$GITHUB_WORKSPACE"
oc login --token="${{ env.AUTH_TOKEN }}" --server="$CLUSTER"
export OS_NAMESPACE_SUFFIX=${{ env.OS_NAMESPACE_SUFFIX }}
export START_DATE=${{ env.START_DATE }}
export END_DATE=${{ env.END_DATE }}
make seed-oc-recommitment
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export TEST_EMAIL:=$(TEST_EMAIL)
export TEST_RUN:=$(TEST_RUN)
export VIEWS:=$(VIEWS)
export RECOMMITMENT_MINISTRY:=$(RECOMMITMENT_MINISTRY)

export START_DATE:=$(START_DATE)
export END_DATE:=$(END_DATE)

# Docker compose v2 for GHA
build-test:
Expand Down Expand Up @@ -115,11 +116,21 @@ push-prod:
@docker push $(CONTAINER_REGISTRY)/frontend:latest
@docker push $(CONTAINER_REGISTRY)/backend:latest

open-db-tunnel:
@oc project $(TARGET_NAMESPACE)
open-db-tunnel-dev:
@oc project $(OS_NAMESPACE_PREFIX)-dev
# Use patroni-0 to make EDIT changes, patroni-1 for READ ONLY
@oc port-forward $(APP_NAME)-patroni-0 5432

open-db-tunnel-test:
@oc project $(OS_NAMESPACE_PREFIX)-test
# Use patroni-0 to make EDIT changes, patroni-2 for READ ONLY
@oc port-forward $(APP_NAME)-patroni-2 5432

open-db-tunnel-prod:
@oc project $(OS_NAMESPACE_PREFIX)-prod
# Use patroni-1 for READ ONLY - use patroni-0 to make EDIT changes (please access with caution)
@oc port-forward $(APP_NAME)-patroni-1 5432

### Openshift Setup
db-prep:
@oc process -f openshift/patroni.prep.yml -p APP_NAME=$(APP_NAME) | oc create -n $(TARGET_NAMESPACE) -f -
Expand Down Expand Up @@ -245,7 +256,7 @@ seed-local-ci:
@docker exec tc-backend-${ENV} ./node_modules/.bin/ts-node -e 'require("./src/database/seed/seed.ts")'

seed-local-recommitment:
@docker exec tc-backend-${ENV} ./node_modules/.bin/ts-node -e 'require("./src/database/seed/seed-recommitment.ts")'
@docker exec tc-backend-${ENV} ./node_modules/.bin/ts-node -e 'require("./src/database/seed/seed-recommitment.ts").handler("$(START_DATE)", "$(END_DATE)")'

seed-local-bcws:
@docker exec tc-backend-${ENV} ./node_modules/.bin/ts-node -e 'require("./src/database/seed/seed-bcws.ts")'
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/seed/seed-bcws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const handler = async () => {
const bcwsPersonnelRepo = datasource.getRepository(BcwsPersonnelEntity);

try {
for (let i = 0; i < 50; i++) {
for (let i = 0; i < 500; i++) {
const dateApplied = faker.date.past();
const { personnelData } = createPersonnelHandler(locations, tools, certs);

Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/seed/seed-both.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const handler = async () => {
const emcrPersonnelRepo = datasource.getRepository(EmcrPersonnelEntity);

try {
for (let i = 0; i < 50; i++) {
for (let i = 0; i < 500; i++) {
const dateApplied = faker.date.past();

const { personnelData } = createPersonnelHandler(locations, tools, certs);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/seed/seed-emcr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const handler = async () => {
const emcrPersonnelRepo = datasource.getRepository(EmcrPersonnelEntity);

try {
for (let i = 0; i < 50; i++) {
for (let i = 0; i < 500; i++) {
const dateApplied = faker.date.past();
const { personnelData } = createPersonnelHandler(locations, tools, certs);

Expand Down
99 changes: 53 additions & 46 deletions backend/src/database/seed/seed-recommitment.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,71 @@
import { datasource } from '../datasource';

import { BcwsPersonnelEntity } from '../entities/bcws';
import { EmcrPersonnelEntity } from '../entities/emcr';
import { PersonnelEntity } from '../entities/personnel/personnel.entity';
import { RecommitmentCycleEntity } from '../entities/recommitment/recommitment-cycle.entity';
import { RecommitmentEntity } from '../entities/recommitment/recommitment.entity';
import { Program } from '../../auth/interface';
import { Status } from '../../common/enums';
import { RecommitmentStatus } from '../../common/enums/recommitment-status.enum';
import { datePST } from '../../common/helpers';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const handler = async () => {
export const handler = async (startDate, endDate) => {
console.log('seeding recommitment...');
if (!datasource.isInitialized) {
await datasource.initialize();
}

const recommitmentCycleRepository = datasource.getRepository(
RecommitmentCycleEntity,
);

console.log('...seeding cycle...');
const cycle = await recommitmentCycleRepository.save(
recommitmentCycleRepository.create({
year: 2025,
startDate: startDate,
endDate: endDate,
}),
);
const recommitmentRepository = datasource.getRepository(RecommitmentEntity);
const startDate = new Date(datePST(new Date()));
await recommitmentCycleRepository.save(recommitmentCycleRepository.create(new RecommitmentCycleEntity(startDate, new Date(), new Date().getFullYear()) ));

const personnelRepository = datasource.getRepository(PersonnelEntity);

const bcwsPersonnelRepository = datasource.getRepository(BcwsPersonnelEntity);
const emcrPersonnelRepository = datasource.getRepository(EmcrPersonnelEntity);
const emcrPersonnelQB = personnelRepository
.createQueryBuilder('emcr_personnel')
.where('status = :status', { status: Status.ACTIVE });
const bcwsPersonnelQB = personnelRepository
.createQueryBuilder('bcws_personnel')
.where('status = :status', { status: Status.ACTIVE });

const bcwsPersonnelRepositoryQB =
bcwsPersonnelRepository.createQueryBuilder('bcwsPersonnel');
const emcrPersonnelRepositoryQB =
emcrPersonnelRepository.createQueryBuilder('emcrPersonnel');
const bcwsPersonnel = await bcwsPersonnelRepositoryQB.getMany();
const emcrPersonnel = await emcrPersonnelRepositoryQB.getMany();
const emcrPersonnel = await emcrPersonnelQB.getMany();
const bcwsPersonnel = await bcwsPersonnelQB.getMany();
console.log('...');
console.log('...seeding emcr...');
console.log('...');
for (const person of emcrPersonnel) {
await recommitmentRepository.save(
recommitmentRepository.create({
personnelId: person.id,
recommitmentCycleId: cycle.year,
status: RecommitmentStatus.PENDING,
memberDecisionDate: null,
supervisorIdir: null,
supervisorDecisionDate: null,
program: Program.EMCR,
}),
);
}

emcrPersonnel.forEach(async (person: EmcrPersonnelEntity) => {
const emcrRecommitment = recommitmentRepository.create({
personnelId: person.personnelId,
recommitmentCycleId: new Date().getFullYear(),
status: RecommitmentStatus.PENDING,
memberDecisionDate: null,
memberReason: null,
supervisorIdir: null,
supervisorDecisionDate: null,
program: Program.EMCR,
});
await recommitmentRepository.save(emcrRecommitment);
});
bcwsPersonnel.forEach(async (person: BcwsPersonnelEntity) => {
const bcwsRecommitment = recommitmentRepository.create({
personnelId: person.personnelId,
recommitmentCycleId: new Date().getFullYear(),
status: RecommitmentStatus.PENDING,
memberDecisionDate: null,
memberReason: null,
supervisorIdir: null,
supervisorDecisionDate: null,
program: Program.BCWS,
});
await recommitmentRepository.save(bcwsRecommitment);
});
console.log('...seeding bcws...');
console.log('...');
for (const person of bcwsPersonnel) {
await recommitmentRepository.save(
recommitmentRepository.create({
personnelId: person.id,
recommitmentCycleId: cycle.year,
status: RecommitmentStatus.PENDING,
memberDecisionDate: null,
supervisorIdir: null,
supervisorDecisionDate: null,
program: Program.BCWS,
}),
);
}
console.log('...seeding recommitment complete');
};

handler();
29 changes: 0 additions & 29 deletions backend/src/jobs/seed-recommitment.ts

This file was deleted.

26 changes: 0 additions & 26 deletions backend/src/recommitment/recommitment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,32 +369,6 @@ export class RecommitmentService {
return;
}

/**
* Saves recommitment entities for the given personnel.
* @param {PersonnelEntity[]} personnel - The personnel array.
* @param {number} year - The recommitment cycle year.
* @param {Program} program - The program.
*/
private async saveRecommitmentEntities(
personnel: PersonnelEntity[],
year: number,
program: Program,
): Promise<void> {
for (const person of personnel) {
await this.recommitmentRepository.save(
this.recommitmentRepository.create({
personnelId: person.id,
recommitmentCycleId: year,
status: RecommitmentStatus.PENDING,
memberDecisionDate: null,
supervisorIdir: null,
supervisorDecisionDate: null,
program,
}),
);
}
}

/**
* Sends automated reminders to members and supervisors.
* @param {boolean} dryRun - If true, the process will not make any changes.
Expand Down
Loading