feat: query past year colles
This commit is contained in:
parent
ede2eba681
commit
15a435e5a3
2 changed files with 18 additions and 8 deletions
|
|
@ -25,7 +25,7 @@ export default class CollesController {
|
|||
const endDate = startDate.plus({ days: 6 }) // Sunday
|
||||
|
||||
// Retrieve colles for the authenticated user
|
||||
const data = await this.service.getColles(auth.user!, startDate.toISO(), endDate.toISO())
|
||||
const data = await this.service.getColles(auth.user!, startDate, endDate)
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import Room from '#models/room'
|
|||
import Subject from '#models/subject'
|
||||
import User from '#models/user'
|
||||
import redis from '@adonisjs/redis/services/main'
|
||||
import { DateTime } from 'luxon'
|
||||
|
||||
export class ColleService {
|
||||
async getHealthyUntil(className: string) {
|
||||
|
|
@ -69,15 +70,15 @@ export class ColleService {
|
|||
return room
|
||||
}
|
||||
|
||||
async getColles(student: User, startDate: string, endDate: string) {
|
||||
async getColles(student: User, startDate: DateTime, endDate: DateTime) {
|
||||
const classColles = await Colle.query()
|
||||
.preload('student')
|
||||
.preload('examiner')
|
||||
.preload('subject')
|
||||
.preload('room')
|
||||
.preload('attachments')
|
||||
.where('date', '>=', startDate)
|
||||
.where('date', '<=', endDate)
|
||||
.where('date', '>=', startDate.toISO()!)
|
||||
.where('date', '<=', endDate.toISO()!)
|
||||
.whereHas('student', (query) => {
|
||||
query.where('className', student.className)
|
||||
})
|
||||
|
|
@ -85,17 +86,26 @@ export class ColleService {
|
|||
.whereNotNull('grade')
|
||||
.orderBy('date', 'asc')
|
||||
|
||||
const studentColles = await Colle.query()
|
||||
const studentCollesQuery = Colle.query()
|
||||
.preload('student')
|
||||
.preload('examiner')
|
||||
.preload('subject')
|
||||
.preload('room')
|
||||
.preload('attachments')
|
||||
.where('date', '>=', startDate)
|
||||
.where('date', '<=', endDate)
|
||||
.where('studentId', student.id)
|
||||
.where('date', '>=', startDate.toISO()!)
|
||||
.where('date', '<=', endDate.toISO()!)
|
||||
.orderBy('date', 'asc')
|
||||
|
||||
if (student.pastStudentId) {
|
||||
studentCollesQuery.where((query) => {
|
||||
query.where('studentId', student.id).orWhere('studentId', student.pastStudentId!)
|
||||
})
|
||||
} else {
|
||||
studentCollesQuery.where('studentId', student.id)
|
||||
}
|
||||
|
||||
const studentColles = await studentCollesQuery
|
||||
|
||||
// TODO: Favorite colles
|
||||
const favoriteColles = [] as Colle[]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue