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
|
const endDate = startDate.plus({ days: 6 }) // Sunday
|
||||||
|
|
||||||
// Retrieve colles for the authenticated user
|
// 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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data,
|
data,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import Room from '#models/room'
|
||||||
import Subject from '#models/subject'
|
import Subject from '#models/subject'
|
||||||
import User from '#models/user'
|
import User from '#models/user'
|
||||||
import redis from '@adonisjs/redis/services/main'
|
import redis from '@adonisjs/redis/services/main'
|
||||||
|
import { DateTime } from 'luxon'
|
||||||
|
|
||||||
export class ColleService {
|
export class ColleService {
|
||||||
async getHealthyUntil(className: string) {
|
async getHealthyUntil(className: string) {
|
||||||
|
|
@ -69,15 +70,15 @@ export class ColleService {
|
||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
|
|
||||||
async getColles(student: User, startDate: string, endDate: string) {
|
async getColles(student: User, startDate: DateTime, endDate: DateTime) {
|
||||||
const classColles = await Colle.query()
|
const classColles = await Colle.query()
|
||||||
.preload('student')
|
.preload('student')
|
||||||
.preload('examiner')
|
.preload('examiner')
|
||||||
.preload('subject')
|
.preload('subject')
|
||||||
.preload('room')
|
.preload('room')
|
||||||
.preload('attachments')
|
.preload('attachments')
|
||||||
.where('date', '>=', startDate)
|
.where('date', '>=', startDate.toISO()!)
|
||||||
.where('date', '<=', endDate)
|
.where('date', '<=', endDate.toISO()!)
|
||||||
.whereHas('student', (query) => {
|
.whereHas('student', (query) => {
|
||||||
query.where('className', student.className)
|
query.where('className', student.className)
|
||||||
})
|
})
|
||||||
|
|
@ -85,17 +86,26 @@ export class ColleService {
|
||||||
.whereNotNull('grade')
|
.whereNotNull('grade')
|
||||||
.orderBy('date', 'asc')
|
.orderBy('date', 'asc')
|
||||||
|
|
||||||
const studentColles = await Colle.query()
|
const studentCollesQuery = Colle.query()
|
||||||
.preload('student')
|
.preload('student')
|
||||||
.preload('examiner')
|
.preload('examiner')
|
||||||
.preload('subject')
|
.preload('subject')
|
||||||
.preload('room')
|
.preload('room')
|
||||||
.preload('attachments')
|
.preload('attachments')
|
||||||
.where('date', '>=', startDate)
|
.where('date', '>=', startDate.toISO()!)
|
||||||
.where('date', '<=', endDate)
|
.where('date', '<=', endDate.toISO()!)
|
||||||
.where('studentId', student.id)
|
|
||||||
.orderBy('date', 'asc')
|
.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
|
// TODO: Favorite colles
|
||||||
const favoriteColles = [] as Colle[]
|
const favoriteColles = [] as Colle[]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue