Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [BE] add promise return type to findByCategory function and update toJSON method additional fields #41

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading