67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { Controller, Get, Post, Inject, Query, Body } from '@midwayjs/core';
|
|
import { successResponse, errorResponse } from '../utils/response.util';
|
|
import { CustomerService } from '../service/customer.service';
|
|
import { QueryCustomerListDTO, CustomerTagDTO } from '../dto/customer.dto';
|
|
import { ApiOkResponse } from '@midwayjs/swagger';
|
|
|
|
@Controller('/customer')
|
|
export class CustomerController {
|
|
@Inject()
|
|
customerService: CustomerService;
|
|
|
|
@ApiOkResponse({ type: Object })
|
|
@Get('/getcustomerlist')
|
|
async getCustomerList(@Query() query: QueryCustomerListDTO) {
|
|
try {
|
|
const result = await this.customerService.getCustomerList(query as any);
|
|
return successResponse(result);
|
|
} catch (error) {
|
|
return errorResponse(error.message);
|
|
}
|
|
}
|
|
|
|
@ApiOkResponse({ type: Object })
|
|
@Post('/addtag')
|
|
async addTag(@Body() body: CustomerTagDTO) {
|
|
try {
|
|
const result = await this.customerService.addTag(body.email, body.tag);
|
|
return successResponse(result);
|
|
} catch (error) {
|
|
return errorResponse(error.message);
|
|
}
|
|
}
|
|
|
|
@ApiOkResponse({ type: Object })
|
|
@Post('/deltag')
|
|
async delTag(@Body() body: CustomerTagDTO) {
|
|
try {
|
|
const result = await this.customerService.delTag(body.email, body.tag);
|
|
return successResponse(result);
|
|
} catch (error) {
|
|
return errorResponse(error.message);
|
|
}
|
|
}
|
|
|
|
@ApiOkResponse({ type: Object })
|
|
@Get('/gettags')
|
|
async getTags() {
|
|
try {
|
|
const result = await this.customerService.getTags();
|
|
return successResponse(result);
|
|
} catch (error) {
|
|
return errorResponse(error.message);
|
|
}
|
|
}
|
|
|
|
@ApiOkResponse({ type: Object })
|
|
@Post('/setrate')
|
|
async setRate(@Body() body: { id: number; rate: number }) {
|
|
try {
|
|
const result = await this.customerService.setRate({ id: body.id, rate: body.rate });
|
|
return successResponse(result);
|
|
} catch (error) {
|
|
return errorResponse(error.message);
|
|
}
|
|
}
|
|
}
|