83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import {
|
|
Body,
|
|
Context,
|
|
Controller,
|
|
Del,
|
|
Get,
|
|
Inject,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
} from '@midwayjs/core';
|
|
import { CustomerService } from '../service/customer.service';
|
|
import { errorResponse, successResponse } from '../utils/response.util';
|
|
import { ApiOkResponse } from '@midwayjs/swagger';
|
|
import { BooleanRes } from '../dto/reponse.dto';
|
|
import { CustomerTagDTO, QueryCustomerListDTO } from '../dto/customer.dto';
|
|
|
|
@Controller('/customer')
|
|
export class CustomerController {
|
|
@Inject()
|
|
ctx: Context;
|
|
|
|
@Inject()
|
|
customerService: CustomerService;
|
|
|
|
@ApiOkResponse()
|
|
@Get('/list')
|
|
async getCustomerList(@Query() param: QueryCustomerListDTO) {
|
|
try {
|
|
const data = await this.customerService.getCustomerList(param);
|
|
return successResponse(data);
|
|
} catch (error) {
|
|
console.log(error)
|
|
return errorResponse(error?.message || error);
|
|
}
|
|
}
|
|
|
|
@ApiOkResponse({ type: BooleanRes })
|
|
@Post('/tag/add')
|
|
async addTag(@Body() dto: CustomerTagDTO) {
|
|
try {
|
|
await this.customerService.addTag(dto.email, dto.tag);
|
|
return successResponse(true);
|
|
} catch (error) {
|
|
return errorResponse(error?.message || error);
|
|
}
|
|
}
|
|
|
|
@ApiOkResponse({ type: BooleanRes })
|
|
@Del('/tag/del')
|
|
async delTag(@Body() dto: CustomerTagDTO) {
|
|
try {
|
|
await this.customerService.delTag(dto.email, dto.tag);
|
|
return successResponse(true);
|
|
} catch (error) {
|
|
return errorResponse(error?.message || error);
|
|
}
|
|
}
|
|
|
|
@ApiOkResponse()
|
|
@Get('/tags')
|
|
async getTags() {
|
|
try {
|
|
const data = await this.customerService.getTags();
|
|
return successResponse(data);
|
|
} catch (error) {
|
|
return errorResponse(error?.message || error);
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOkResponse({ type: BooleanRes })
|
|
@Put('/rate')
|
|
async setRate(@Body() params: { id: number; rate: number }) {
|
|
try {
|
|
await this.customerService.setRate(params);
|
|
return successResponse(true);
|
|
} catch (error) {
|
|
return errorResponse(error?.message || error);
|
|
}
|
|
}
|
|
}
|