Skip to content
Merged

Dev #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"joi": "^17.13.3",
"mongoose": "^9.2.4",
"morgan": "^1.10.1",
"multer": "^2.1.1",
"nestjs-telegraf": "^2.9.1",
"nestjs-vnpay": "^1.0.4",
"node-cache": "^5.1.2",
Expand Down
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/modules/campaign/campaign-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ export class CampaignOrderService {
}

private generateOrderCode(): string {
const timestamp = Date.now().toString(36).toUpperCase();
const isDev = process.env.NODE_ENV !== 'production';
const prefix = isDev ? '5SPORTDEV' : '5SPORT';
const timestamp = Date.now();
const random = Math.random().toString(36).substring(2, 6).toUpperCase();
return `ORD-${timestamp}-${random}`;
return `${prefix}-${timestamp}-${random}`;
}
}
9 changes: 7 additions & 2 deletions src/modules/upload/upload.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
BadRequestException,
Controller,
Post,
UploadedFile,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { memoryStorage } from 'multer';
import { UploadService } from './upload.service';
import { ApiBearerAuth, ApiBody, ApiConsumes } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
Expand All @@ -16,7 +18,7 @@ export class UploadController {

@Post('')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiBearerAuth('JWT-auth')
@ApiConsumes('multipart/form-data')
@ApiBody({
schema: {
Expand All @@ -30,8 +32,11 @@ export class UploadController {
},
},
})
@UseInterceptors(FileInterceptor('file'))
@UseInterceptors(FileInterceptor('file', { storage: memoryStorage() }))
uploadFile(@UploadedFile() file: Express.Multer.File) {
if (!file) {
throw new BadRequestException('No file uploaded');
}
return this.uploadService.uploadFile(file);
}
}
5 changes: 4 additions & 1 deletion src/modules/upload/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export class UploadService {

async uploadFile(file: Express.Multer.File): Promise<string | false> {
try {
const key = `${Date.now()}-${file.originalname}`;
const randomString = Math.random().toString(36).substring(2, 15);
const now = new Date();
const date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
const key = `${date}/${randomString}-${file.originalname}`;

const command = new PutObjectCommand({
Bucket: BUCKET_NAME,
Expand Down
Loading