diff --git a/services/apps/assignments/src/assignment/assignment.schema.ts b/services/apps/assignments/src/assignment/assignment.schema.ts index 27fbfa92..343b424c 100644 --- a/services/apps/assignments/src/assignment/assignment.schema.ts +++ b/services/apps/assignments/src/assignment/assignment.schema.ts @@ -195,4 +195,15 @@ export class Assignment { export type AssignmentDocument = Doc; -export const AssignmentSchema = SchemaFactory.createForClass(Assignment); +export const ASSIGNMENT_SORT = { + title: 1, +} as const; + +export const ASSIGNMENT_COLLATION = { + locale: 'en', + numericOrdering: true, +} as const; + +export const AssignmentSchema = SchemaFactory.createForClass(Assignment) + .index(ASSIGNMENT_SORT, {collation: ASSIGNMENT_COLLATION}) +; diff --git a/services/apps/assignments/src/assignment/assignment.service.ts b/services/apps/assignments/src/assignment/assignment.service.ts index 2ba6f4d6..adda4658 100644 --- a/services/apps/assignments/src/assignment/assignment.service.ts +++ b/services/apps/assignments/src/assignment/assignment.service.ts @@ -5,7 +5,7 @@ import {InjectModel} from '@nestjs/mongoose'; import {FilterQuery, Model, Types, UpdateQuery} from 'mongoose'; import {generateToken} from '../utils'; import {CreateAssignmentDto, ReadAssignmentDto, ReadTaskDto, UpdateAssignmentDto} from './assignment.dto'; -import {Assignment, AssignmentDocument, Task} from './assignment.schema'; +import {Assignment, ASSIGNMENT_COLLATION, ASSIGNMENT_SORT, AssignmentDocument, Task} from './assignment.schema'; import {MemberService} from "@app/member"; @Injectable() @@ -42,9 +42,9 @@ export class AssignmentService { } async findAll(where: FilterQuery = {}): Promise { - return this.model.find(where).sort({title: 1}).collation({ - locale: 'en', - numericOrdering: true, + return this.model.find(where, undefined,{ + sort: ASSIGNMENT_SORT, + collation: ASSIGNMENT_COLLATION, }).exec(); }