-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and handle villages for given country queries
- Loading branch information
Showing
6 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { SelectQueryBuilder } from 'typeorm'; | ||
|
||
import { getPhasePeriod, phaseWasSelected } from '.'; | ||
import type { Student } from '../../entities/student'; | ||
import type { User } from '../../entities/user'; | ||
import type { Village, VillagePhase } from '../../entities/village'; | ||
|
||
export const addPhaseFilteringToQuery = async <T extends User | Student>(query: SelectQueryBuilder<T>, phase: VillagePhase, village: Village) => { | ||
if (phaseWasSelected(phase)) { | ||
const phaseValue = phase as number; | ||
const { debut, end } = await getPhasePeriod(village.id, phaseValue); | ||
query.andWhere('student.createdAt >= :debut', { debut }); | ||
if (phaseValue != village?.activePhase) query.andWhere('student.createdAt <= :end', { end }); | ||
} | ||
return query; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Student } from '../../entities/student'; | ||
import { AppDataSource } from '../../utils/data-source'; | ||
|
||
const studentRepository = AppDataSource.getRepository(Student); | ||
export const createChildrenCodesQuery = () => { | ||
const query = studentRepository.createQueryBuilder('student').innerJoin('student.classroom', 'classroom').innerJoin('classroom.village', 'village'); | ||
return query; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Student } from '../../entities/student'; | ||
import { AppDataSource } from '../../utils/data-source'; | ||
|
||
const studentRepository = AppDataSource.getRepository(Student); | ||
export const createConnectedFamilyQuery = () => { | ||
const query = studentRepository | ||
.createQueryBuilder('student') | ||
.innerJoin('classroom', 'classroom', 'classroom.id = student.classroomId') | ||
.andWhere('student.numLinkedAccount >= 1'); | ||
return query; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters