create-chuntianxiaozhu
Version:
春天小猪模板工具
41 lines (38 loc) • 1.26 kB
text/typescript
import { Body, Controller, Post, Req } from '@nestjs/common';
import { AddTicketsDto } from './dtos/add-tickets.dto';
import { TicketsService } from '../../common/tickets.service';
import { v4 as uuidv4 } from 'uuid';
import { Roles } from 'api/utils/decorator';
import { RoleEnum } from 'api/utils/constants';
import { ExchangeWalletDto } from './dtos/exchange-wallet.dto';
import { Request } from 'express';
import { getUid } from 'api/utils/utils';
('tickets')
export class TicketsController {
constructor(private ticketsService: TicketsService) {}
('add')
(RoleEnum.SuperAdmin)
async add(() addTicketsDto: AddTicketsDto) {
const { amount, num } = addTicketsDto;
let textStr = '';
for (let i = 0; i < num; i++) {
const password = uuidv4().replaceAll('-', '').toUpperCase();
this.ticketsService.save({
amount: amount * 100,
password,
});
textStr += `${password}\n`;
}
return textStr;
}
('exchange')
async exchange(
() req: Request,
() exchangeWalletDto: ExchangeWalletDto,
) {
const uid = getUid(req);
const { password } = exchangeWalletDto;
await this.ticketsService.recharge(uid, password);
return true;
}
}