zs 1 vuosi sitten
vanhempi
commit
9a7477d5cf
2 muutettua tiedostoa jossa 21 lisäystä ja 0 poistoa
  1. 7 0
      src/controller/Good.controller.ts
  2. 14 0
      src/service/Good.service.ts

+ 7 - 0
src/controller/Good.controller.ts

@@ -53,6 +53,13 @@ export class GoodController extends BaseController {
     return { data, total };
   }
 
+  @Get('/search')
+  @ApiQuery({ name: 'search' })
+  async search(@Query() filter: any) {
+    const list: any = await this.service.search(filter);
+    return list;
+  }
+
   @Get('/:id')
   @ApiResponse({ type: FVO_Good })
   async fetch(@Param('id') id: string) {

+ 14 - 0
src/service/Good.service.ts

@@ -8,4 +8,18 @@ type modelType = ReturnModelType<typeof Good>;
 export class GoodService extends BaseService<modelType> {
   @InjectEntityModel(Good)
   model: modelType;
+
+  async search(filter): Promise<object> {
+    const { name, is_use } = filter;
+    const list = await this.model.aggregate([
+      { $match: { name: { $regex: name }, is_use: is_use } },
+      {
+        $project: {
+          _id: 1,
+          name: 1,
+        },
+      },
+    ]);
+    return list;
+  }
 }