feat: show past colles
This commit is contained in:
parent
77213340b6
commit
cc817cf9a7
1 changed files with 44 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import Colle from '#models/colle'
|
import Colle from '#models/colle'
|
||||||
|
import User from '#models/user'
|
||||||
import { ColleService } from '#services/colle_service'
|
import { ColleService } from '#services/colle_service'
|
||||||
import { NotificationService } from '#services/notification_service'
|
import { NotificationService } from '#services/notification_service'
|
||||||
import { createColleValidator, createUpcomingCollesValidator } from '#validators/colle'
|
import { createColleValidator, createUpcomingCollesValidator } from '#validators/colle'
|
||||||
|
|
@ -38,7 +39,7 @@ export default class CollesController {
|
||||||
return response.badRequest({ message: 'Invalid colle ID' })
|
return response.badRequest({ message: 'Invalid colle ID' })
|
||||||
}
|
}
|
||||||
// Retrieve the colle by ID
|
// Retrieve the colle by ID
|
||||||
const colle = await Colle.query()
|
let colle = await Colle.query()
|
||||||
.where('id', colleId)
|
.where('id', colleId)
|
||||||
.whereHas('student', (query) => {
|
.whereHas('student', (query) => {
|
||||||
query.where('className', auth.user!.className)
|
query.where('className', auth.user!.className)
|
||||||
|
|
@ -49,6 +50,28 @@ export default class CollesController {
|
||||||
.preload('room')
|
.preload('room')
|
||||||
.preload('attachments')
|
.preload('attachments')
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
let className = auth.user!.className
|
||||||
|
|
||||||
|
// If colle not found and user has a past student ID, try with the past student's class
|
||||||
|
if (!colle && auth.user!.pastStudentId) {
|
||||||
|
const pastUser = await User.find(auth.user!.pastStudentId)
|
||||||
|
if (pastUser) {
|
||||||
|
className = pastUser.className
|
||||||
|
colle = await Colle.query()
|
||||||
|
.where('id', colleId)
|
||||||
|
.whereHas('student', (query) => {
|
||||||
|
query.where('className', pastUser.className)
|
||||||
|
})
|
||||||
|
.preload('student')
|
||||||
|
.preload('examiner')
|
||||||
|
.preload('subject')
|
||||||
|
.preload('room')
|
||||||
|
.preload('attachments')
|
||||||
|
.first()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!colle) {
|
if (!colle) {
|
||||||
return response.notFound({ message: 'Colle not found' })
|
return response.notFound({ message: 'Colle not found' })
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +82,7 @@ export default class CollesController {
|
||||||
.where('id', '!=', colle.id) // Exclude the current colle
|
.where('id', '!=', colle.id) // Exclude the current colle
|
||||||
.where('examinerId', colle.examinerId)
|
.where('examinerId', colle.examinerId)
|
||||||
.whereHas('student', (query) => {
|
.whereHas('student', (query) => {
|
||||||
query.where('className', auth.user!.className)
|
query.where('className', className)
|
||||||
})
|
})
|
||||||
.preload('student')
|
.preload('student')
|
||||||
|
|
||||||
|
|
@ -81,12 +104,28 @@ export default class CollesController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the colle by ID
|
// Retrieve the colle by ID
|
||||||
const colle = await Colle.query()
|
let colle = await Colle.query()
|
||||||
.where('id', colleId)
|
.where('id', colleId)
|
||||||
.whereHas('student', (query) => {
|
.whereHas('student', (query) => {
|
||||||
query.where('className', auth.user!.className)
|
query.where('className', auth.user!.className)
|
||||||
})
|
})
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
let className = auth.user!.className
|
||||||
|
|
||||||
|
if (!colle && auth.user!.pastStudentId) {
|
||||||
|
const pastUser = await User.find(auth.user!.pastStudentId)
|
||||||
|
if (pastUser) {
|
||||||
|
className = pastUser.className
|
||||||
|
colle = await Colle.query()
|
||||||
|
.where('id', colleId)
|
||||||
|
.whereHas('student', (query) => {
|
||||||
|
query.where('className', pastUser.className)
|
||||||
|
})
|
||||||
|
.first()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!colle) {
|
if (!colle) {
|
||||||
return response.notFound({ message: 'Colle not found' })
|
return response.notFound({ message: 'Colle not found' })
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +138,7 @@ export default class CollesController {
|
||||||
type: 0, // Refresh colle
|
type: 0, // Refresh colle
|
||||||
colle_id: colle.bjid,
|
colle_id: colle.bjid,
|
||||||
colle_secret: colle.bjsecret,
|
colle_secret: colle.bjsecret,
|
||||||
class_name: auth.user!.className,
|
class_name: className,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -109,7 +148,7 @@ export default class CollesController {
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 1, // Search for colles on a specific day
|
type: 1, // Search for colles on a specific day
|
||||||
date: colle.date.toFormat('dd/MM/yyyy'),
|
date: colle.date.toFormat('dd/MM/yyyy'),
|
||||||
class_name: auth.user!.className,
|
class_name: className,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue