Compare commits
No commits in common. "15a435e5a3cfe561967599f9d4e3a94f4a1eea55" and "71d0a35478a27a19ab5b041113b8213f0502c275" have entirely different histories.
15a435e5a3
...
71d0a35478
9 changed files with 19 additions and 105 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, endDate)
|
const data = await this.service.getColles(auth.user!, startDate.toISO(), endDate.toISO())
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data,
|
data,
|
||||||
|
|
@ -187,9 +187,9 @@ export default class CollesController {
|
||||||
parseFloat(beforeColle.grade)
|
parseFloat(beforeColle.grade)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (hasChanged(beforeColle, afterColle)) {
|
// if (!deepEqual(beforeColle, afterColle)) {
|
||||||
await this.notificationService.sendNotification('COLLE_UPDATED', existing)
|
// await this.notificationService.sendNotification('COLLE_UPDATED', existing)
|
||||||
}
|
// }
|
||||||
return existing.save()
|
return existing.save()
|
||||||
}
|
}
|
||||||
const colle = await Colle.create(colleData)
|
const colle = await Colle.create(colleData)
|
||||||
|
|
@ -269,9 +269,9 @@ export default class CollesController {
|
||||||
const afterColle = oldColle.serialize()
|
const afterColle = oldColle.serialize()
|
||||||
upcomingCollesIds.delete(oldColle.id)
|
upcomingCollesIds.delete(oldColle.id)
|
||||||
|
|
||||||
if (beforeColle.roomId !== afterColle.roomId) {
|
if (beforeColle.room !== afterColle.room) {
|
||||||
await this.notificationService.sendNotification('ROOM_UPDATED', oldColle)
|
await this.notificationService.sendNotification('ROOM_UPDATED', oldColle)
|
||||||
} else if (hasChanged(beforeColle, afterColle)) {
|
} else if (!deepEqual(beforeColle, afterColle)) {
|
||||||
await this.notificationService.sendNotification('COLLE_UPDATED', oldColle)
|
await this.notificationService.sendNotification('COLLE_UPDATED', oldColle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -298,16 +298,6 @@ export default class CollesController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const propsToCheck = [
|
function deepEqual(a: any, b: any) {
|
||||||
'examinerId',
|
return JSON.stringify(a) === JSON.stringify(b)
|
||||||
'bjsecret',
|
}
|
||||||
'bjid',
|
|
||||||
'grade',
|
|
||||||
'content',
|
|
||||||
'comment',
|
|
||||||
'roomId',
|
|
||||||
'date',
|
|
||||||
'subjectId',
|
|
||||||
]
|
|
||||||
const hasChanged = (beforeColle: any, afterColle: any) =>
|
|
||||||
propsToCheck.some((prop) => beforeColle[prop] !== afterColle[prop])
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import { SubjectService } from '#services/subject_service'
|
import { SubjectService } from '#services/subject_service'
|
||||||
import { updateUserValidator, matchStudentValidator, mergeStudentValidator } from '#validators/user'
|
import { updateUserValidator } from '#validators/user'
|
||||||
import { inject } from '@adonisjs/core'
|
import { inject } from '@adonisjs/core'
|
||||||
import type { HttpContext } from '@adonisjs/core/http'
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
import User from '#models/user'
|
|
||||||
|
|
||||||
@inject()
|
@inject()
|
||||||
export default class UserController {
|
export default class UserController {
|
||||||
|
|
@ -55,32 +54,4 @@ export default class UserController {
|
||||||
data: user,
|
data: user,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /match-student
|
|
||||||
async matchStudent({ request, response }: HttpContext) {
|
|
||||||
const { firstName, lastName, classId } = await request.validateUsing(matchStudentValidator)
|
|
||||||
|
|
||||||
const user = await User.query()
|
|
||||||
.where('firstName', firstName)
|
|
||||||
.andWhere('lastName', lastName)
|
|
||||||
.andWhere('className', classId)
|
|
||||||
.first()
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
return response.notFound({ message: 'User not found' })
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: true, data: user }
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST /merge-student
|
|
||||||
async mergeStudent({ request, auth }: HttpContext) {
|
|
||||||
const user = auth.user!
|
|
||||||
const { pastStudentId } = await request.validateUsing(mergeStudentValidator)
|
|
||||||
|
|
||||||
user.pastStudentId = pastStudentId
|
|
||||||
await user.save()
|
|
||||||
|
|
||||||
return { success: true, data: user }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,6 @@ export default class User extends BaseModel {
|
||||||
@column({ isPrimary: true })
|
@column({ isPrimary: true })
|
||||||
declare id: number
|
declare id: number
|
||||||
|
|
||||||
@column()
|
|
||||||
declare pastStudentId: number | null
|
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
declare className: string
|
declare className: string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ 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) {
|
||||||
|
|
@ -70,15 +69,15 @@ export class ColleService {
|
||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
|
|
||||||
async getColles(student: User, startDate: DateTime, endDate: DateTime) {
|
async getColles(student: User, startDate: string, endDate: string) {
|
||||||
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.toISO()!)
|
.where('date', '>=', startDate)
|
||||||
.where('date', '<=', endDate.toISO()!)
|
.where('date', '<=', endDate)
|
||||||
.whereHas('student', (query) => {
|
.whereHas('student', (query) => {
|
||||||
query.where('className', student.className)
|
query.where('className', student.className)
|
||||||
})
|
})
|
||||||
|
|
@ -86,26 +85,17 @@ export class ColleService {
|
||||||
.whereNotNull('grade')
|
.whereNotNull('grade')
|
||||||
.orderBy('date', 'asc')
|
.orderBy('date', 'asc')
|
||||||
|
|
||||||
const studentCollesQuery = Colle.query()
|
const studentColles = 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.toISO()!)
|
.where('date', '>=', startDate)
|
||||||
.where('date', '<=', endDate.toISO()!)
|
.where('date', '<=', endDate)
|
||||||
|
.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[]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ export class GradeService {
|
||||||
|
|
||||||
while (periodStartDate < startDate.plus({ months })) {
|
while (periodStartDate < startDate.plus({ months })) {
|
||||||
const periodEndDate = periodStartDate.endOf('month')
|
const periodEndDate = periodStartDate.endOf('month')
|
||||||
const periodColles = this.getPeriodColles(colles, periodStartDate, periodEndDate)
|
const periodColles = this.getPeriodColles(colles, startDate, periodEndDate)
|
||||||
|
|
||||||
const periodAverage = this.calculateAverage(periodColles)
|
const periodAverage = this.calculateAverage(periodColles)
|
||||||
const subjectAverages = await this.getSubjectAverages(
|
const subjectAverages = await this.getSubjectAverages(
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export class NotificationService {
|
||||||
if (notificationId === 'ROOM_UPDATED') {
|
if (notificationId === 'ROOM_UPDATED') {
|
||||||
await colle.load('room')
|
await colle.load('room')
|
||||||
}
|
}
|
||||||
const payload = Object.assign({}, DEFAULT_NOTIFICATION, NOTIFICATIONS[notificationId](colle, args))
|
const payload = Object.assign(DEFAULT_NOTIFICATION, NOTIFICATIONS[notificationId](colle, args))
|
||||||
|
|
||||||
const subscriptions = await Subscription.query()
|
const subscriptions = await Subscription.query()
|
||||||
.where('enabled', true)
|
.where('enabled', true)
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,3 @@ export const updateUserValidator = vine.compile(
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
export const matchStudentValidator = vine.compile(
|
|
||||||
vine.object({
|
|
||||||
firstName: vine.string(),
|
|
||||||
lastName: vine.string(),
|
|
||||||
classId: vine.string(),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
export const mergeStudentValidator = vine.compile(
|
|
||||||
vine.object({
|
|
||||||
pastStudentId: vine.number(),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
import { BaseSchema } from '@adonisjs/lucid/schema'
|
|
||||||
|
|
||||||
export default class extends BaseSchema {
|
|
||||||
protected tableName = 'add_past_student_id_to_users'
|
|
||||||
|
|
||||||
async up() {
|
|
||||||
this.schema.createTable(this.tableName, (table) => {
|
|
||||||
table.increments('id')
|
|
||||||
|
|
||||||
table.timestamp('created_at')
|
|
||||||
table.timestamp('updated_at')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async down() {
|
|
||||||
this.schema.dropTable(this.tableName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -39,8 +39,6 @@ router
|
||||||
const UserController = () => import('#controllers/user_controller')
|
const UserController = () => import('#controllers/user_controller')
|
||||||
router.get('/users/@me', [UserController, 'me']).use(middleware.auth())
|
router.get('/users/@me', [UserController, 'me']).use(middleware.auth())
|
||||||
router.post('/users/@me', [UserController, 'update']).use(middleware.auth())
|
router.post('/users/@me', [UserController, 'update']).use(middleware.auth())
|
||||||
router.get('/match-student', [UserController, 'matchStudent']).use(middleware.auth())
|
|
||||||
router.post('/merge-student', [UserController, 'mergeStudent']).use(middleware.auth())
|
|
||||||
|
|
||||||
const SubjectsController = () => import('#controllers/subjects_controller')
|
const SubjectsController = () => import('#controllers/subjects_controller')
|
||||||
router.get('/subjects', [SubjectsController, 'index']).use(middleware.auth())
|
router.get('/subjects', [SubjectsController, 'index']).use(middleware.auth())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue