import { Controller, Get, Post, Put, Del, Inject, Query, Body, Param } from "@midwayjs/core"; import { Context } from "@midwayjs/koa"; import { CustomerService } from "../service/customer.service"; @Controller("/api/customers") export class CustomerController { @Inject() ctx!: Context; @Inject() customerService!: CustomerService; @Get("/") async list(@Query() query: any) { const result = await this.customerService.list(query, this.ctx); return result; } @Get("/options/all") async getSimpleList() { const result = await this.customerService.getSimpleList(this.ctx); return result; } @Get("/:id") async detail(@Param("id") id: string) { const result = await this.customerService.detail(Number(id), this.ctx); return result; } @Post("/") async create(@Body() body: any) { const result = await this.customerService.create(body, this.ctx); return result; } @Put("/:id") async update(@Param("id") id: string, @Body() body: any) { const result = await this.customerService.update(Number(id), body, this.ctx); return result; } @Del("/:id") async delete(@Param("id") id: string) { const result = await this.customerService.delete(Number(id), this.ctx); return result; } @Put("/:id/status") async updateStatus(@Param("id") id: string, @Body() body: { status: number }) { const result = await this.customerService.updateStatus(Number(id), body.status, this.ctx); return result; } }