Skip to content

Commit

Permalink
refactor: [BE] add promise return type to findByCategory function and…
Browse files Browse the repository at this point in the history
… update toJSON method additional fields (#41)
  • Loading branch information
yuchem2 authored and joonamin committed Dec 12, 2024
1 parent 42fd86a commit 5970c3a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/server/src/models/event.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getModelForClass, plugin, prop, ReturnModelType } from '@typegoose/typegoose'
import mongoose from 'mongoose'
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses'
import { User } from '@/models/user'
import mongoosePaginate from 'mongoose-paginate-v2'

import { User } from '@/models/user'

@plugin(mongoosePaginate)
export class Events extends TimeStamps {
static paginate: mongoose.PaginateModel<typeof Events>['paginate']
Expand Down Expand Up @@ -57,6 +58,7 @@ export class Events extends TimeStamps {
return {
_id: this._id,
name: this.name,
address: this.address,
location: this.location,
startDate: this.startDate,
endDate: this.endDate,
Expand All @@ -71,7 +73,11 @@ export class Events extends TimeStamps {
}
}

public static async findByCategory(this: ReturnModelType<typeof Events>, category: string, options: object) {
public static async findByCategory(
this: ReturnModelType<typeof Events>,
category: string,
options: mongoose.PaginateOptions,
): Promise<mongoose.PaginateResult<mongoose.PaginateDocument<typeof Events, object, object, mongoose.PaginateOptions>>> {
return await this.paginate({ category: category }, options)
}
}
Expand Down

0 comments on commit 5970c3a

Please sign in to comment.