From cf101674e71540eae55797b5a1b0694527817793 Mon Sep 17 00:00:00 2001 From: CookieDasora Date: Thu, 1 Feb 2024 18:10:22 +0000 Subject: [PATCH] chore: repo sync --- src/kweeks/dto/create-kweek.dto.ts | 12 +++++++++++- src/kweeks/kweeks.controller.spec.ts | 20 -------------------- src/kweeks/kweeks.controller.ts | 21 ++++++++++++++++++--- src/kweeks/kweeks.module.ts | 8 +++++--- src/kweeks/kweeks.service.spec.ts | 18 ------------------ src/kweeks/kweeks.service.ts | 16 +++++++--------- src/users/users.service.ts | 4 ++-- 7 files changed, 43 insertions(+), 56 deletions(-) delete mode 100644 src/kweeks/kweeks.controller.spec.ts delete mode 100644 src/kweeks/kweeks.service.spec.ts diff --git a/src/kweeks/dto/create-kweek.dto.ts b/src/kweeks/dto/create-kweek.dto.ts index fe28f7e..04a4ca7 100644 --- a/src/kweeks/dto/create-kweek.dto.ts +++ b/src/kweeks/dto/create-kweek.dto.ts @@ -1 +1,11 @@ -export class CreateKweekDto {} +import { createZodDto } from "nestjs-zod"; +import { z } from "nestjs-zod/z"; + +export const CreateKweekSchema = z + .object({ + content: z.string({ required_error: "Kweek content is required" }).max(300), + files: z.array(z.object({})), + }) + .required(); + +export class CreateKweekDTO extends createZodDto(CreateKweekSchema) {} diff --git a/src/kweeks/kweeks.controller.spec.ts b/src/kweeks/kweeks.controller.spec.ts deleted file mode 100644 index ccc08f2..0000000 --- a/src/kweeks/kweeks.controller.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { KweeksController } from './kweeks.controller'; -import { KweeksService } from './kweeks.service'; - -describe('KweeksController', () => { - let controller: KweeksController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [KweeksController], - providers: [KweeksService], - }).compile(); - - controller = module.get(KweeksController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/src/kweeks/kweeks.controller.ts b/src/kweeks/kweeks.controller.ts index b32ad4c..0407f4c 100644 --- a/src/kweeks/kweeks.controller.ts +++ b/src/kweeks/kweeks.controller.ts @@ -6,12 +6,21 @@ import { Patch, Param, Delete, + UseInterceptors, + UploadedFiles, + Request, } from "@nestjs/common"; import { KweeksService } from "./kweeks.service"; -import { CreateKweekDto } from "./dto/create-kweek.dto"; +import { CreateKweekDTO } from "./dto/create-kweek.dto"; import { UpdateKweekDto } from "./dto/update-kweek.dto"; -import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger"; +import { + ApiBearerAuth, + ApiConsumes, + ApiOperation, + ApiTags, +} from "@nestjs/swagger"; import { Public } from "src/public.decorator"; +import { FilesInterceptor } from "@nest-lab/fastify-multer"; @ApiTags("Kweeks") @Controller("kweeks") @@ -21,7 +30,13 @@ export class KweeksController { @Post() @ApiOperation({ summary: "Creates a kweek" }) @ApiBearerAuth("JWT") - create(@Body() createKweekDto: CreateKweekDto) { + @ApiConsumes("multipart/form-data") + @UseInterceptors(FilesInterceptor("attachments", 4)) + create( + @Body() createKweekDto: CreateKweekDTO, + @UploadedFiles() attachments: File, + @Request() req, + ) { return this.kweeksService.create(createKweekDto); } diff --git a/src/kweeks/kweeks.module.ts b/src/kweeks/kweeks.module.ts index 6b84b07..175fc3c 100644 --- a/src/kweeks/kweeks.module.ts +++ b/src/kweeks/kweeks.module.ts @@ -1,8 +1,10 @@ -import { Module } from '@nestjs/common'; -import { KweeksService } from './kweeks.service'; -import { KweeksController } from './kweeks.controller'; +import { Module } from "@nestjs/common"; +import { KweeksService } from "./kweeks.service"; +import { KweeksController } from "./kweeks.controller"; +import { PrismaModule } from "src/prisma/prisma.module"; @Module({ + imports: [PrismaModule], controllers: [KweeksController], providers: [KweeksService], }) diff --git a/src/kweeks/kweeks.service.spec.ts b/src/kweeks/kweeks.service.spec.ts deleted file mode 100644 index aae88f4..0000000 --- a/src/kweeks/kweeks.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { KweeksService } from './kweeks.service'; - -describe('KweeksService', () => { - let service: KweeksService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [KweeksService], - }).compile(); - - service = module.get(KweeksService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/src/kweeks/kweeks.service.ts b/src/kweeks/kweeks.service.ts index 452763b..6489db0 100644 --- a/src/kweeks/kweeks.service.ts +++ b/src/kweeks/kweeks.service.ts @@ -1,15 +1,13 @@ -import { Injectable } from '@nestjs/common'; -import { CreateKweekDto } from './dto/create-kweek.dto'; -import { UpdateKweekDto } from './dto/update-kweek.dto'; +import { Injectable } from "@nestjs/common"; +import { CreateKweekDTO } from "./dto/create-kweek.dto"; +import { UpdateKweekDto } from "./dto/update-kweek.dto"; +import { PrismaService } from "src/prisma/prisma.service"; @Injectable() export class KweeksService { - create(createKweekDto: CreateKweekDto) { - return 'This action adds a new kweek'; - } - - findAll() { - return `This action returns all kweeks`; + constructor(private readonly prisma: PrismaService) {} + create(createKweekDto: CreateKweekDTO) { + return "This action adds a new kweek"; } findOne(id: number) { diff --git a/src/users/users.service.ts b/src/users/users.service.ts index fe2ba67..cbc7845 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -14,8 +14,8 @@ import { S3Service } from "./s3.service"; @Injectable() export class UserService { constructor( - private prisma: PrismaService, - private s3: S3Service, + private readonly prisma: PrismaService, + private readonly s3: S3Service, ) {} async auth_search(username: string): Promise { const user = await this.prisma.user.findFirst({