diff --git a/src/modules/images/repository/mongo/repository.ts b/src/modules/images/repository/mongo/repository.ts index 7cdb1fd..6bb4f8a 100644 --- a/src/modules/images/repository/mongo/repository.ts +++ b/src/modules/images/repository/mongo/repository.ts @@ -5,9 +5,23 @@ import imageSchema from '../../../../database/mongo/schemas/image.schema' class Repository { constructor(private logger: Logger) {} - public async Fetch({ offset, limit }: RequestParams) { - const data = await imageSchema.find().skip(offset).limit(limit) - const count = await imageSchema.find().count() + public async Fetch({ offset, limit, keyword, category }: RequestParams) { + const filter = {} + + if (keyword) + Object.assign(filter, { + title: { + $regex: new RegExp(keyword, 'i'), + }, + }) + + if (category) + Object.assign(filter, { + category: category, + }) + + const data = await imageSchema.find(filter).skip(offset).limit(limit) + const count = await imageSchema.find(filter).count() return { data,