枫叶秋林 пре 2 година
родитељ
комит
c8ce198eb3

+ 2 - 0
prisma/migrations/20221231004543_updata_post_plateid_add_default/migration 2.sql

@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE `post` MODIFY `plateId` INTEGER UNSIGNED NOT NULL DEFAULT 0;

+ 2 - 0
prisma/migrations/20230107033113_userinfo_add_maple_coin/migration 2.sql

@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE `userinfo` ADD COLUMN `mapleCoin` INTEGER UNSIGNED NOT NULL DEFAULT 0;

+ 2 - 0
prisma/migrations/20230107075128_post_add_views/migration 2.sql

@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE `post` ADD COLUMN `views` INTEGER UNSIGNED NOT NULL DEFAULT 0;

+ 2 - 0
prisma/migrations/20230108005603_usset_post_content_varchar_1000/migration 2.sql

@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE `post` MODIFY `content` VARCHAR(10000) NOT NULL;

+ 11 - 1
src/comment/comment.controller.ts

@@ -2,6 +2,7 @@ import { Controller, Get, Post, Body, Param, Delete, UseGuards, Req, Query, Put,
 import { CommentService } from './comment.service'
 import { AuthGuard } from '@nestjs/passport'
 import { CodService } from '@/cod/cod.service'
+import { query } from 'express'
 
 @Controller('comment')
 export class CommentController {
@@ -39,11 +40,20 @@ export class CommentController {
   }
   @Put()
   @UseGuards(AuthGuard('jwt'))
-  async updateComment(@Req() req, @Body() body: any) {
+  async updateComment(@Req() req, @Body() body: any, @Headers('cod') cod: any) {
+    const rescod = await this.codService.verifyCod(req.ip, cod)
+    if (!rescod.status) {
+      return rescod
+    }
     const { Commentid, content } = body
     if (!Commentid || !content) {
       return { status: 400, message: '参数错误' }
     }
     return this.commentService.updateComment(req.user as number, +Commentid, content)
   }
+  @Get('id')
+  async getCommentByid(@Query('commentId') commentId: number) {
+    return this.commentService.getCommentByid(+commentId)
+    // return commentId
+  }
 }

+ 12 - 0
src/comment/comment.service.ts

@@ -85,4 +85,16 @@ export class CommentService {
     })
     return { cod: 200, msg: '修改评论成功', data }
   }
+  //根据id查看某条评论信息
+  async getCommentByid(Commentid: number) {
+    const data = await this.prisma.comment.findFirst({
+      where: {
+        id: Commentid,
+      },
+      select: {
+        content: true,
+      },
+    })
+    return { cod: 200, msg: '获取评论成功', ...data }
+  }
 }

BIN
src/userinfo/dto/.user.dto 2.ts.icloud


BIN
src/userinfo/dto/.userinfo.dto 2.ts.icloud


+ 37 - 0
src/userinfo/userinfo.controller 2.ts

@@ -0,0 +1,37 @@
+import { Body, Controller, Get, Post, Put, Query, Req, UseGuards } from '@nestjs/common'
+import { AuthGuard } from '@nestjs/passport'
+import { UserinfoService } from './userinfo.service'
+import { Request } from 'express'
+import userDateDto from './dto/userinfo.dto'
+import userInfoDto from './dto/user.dto'
+@Controller('userinfo')
+export class UserinfoController {
+  constructor(private readonly userinfoService: UserinfoService) {}
+  @Get()
+  @UseGuards(AuthGuard('jwt'))
+  async getinfo(@Req() req: Request) {
+    return await this.userinfoService.getinfo(req.user as number)
+  }
+  @Get('getuser')
+  async getuser(@Query('id') id: number) {
+    if (id) {
+      return await this.userinfoService.getinfo(+id)
+    } else {
+      return { cod: 400, message: '用户不存在' }
+    }
+  }
+  @Put()
+  @UseGuards(AuthGuard('jwt'))
+  updateinfo(@Req() req: Request, @Body() data: userDateDto) {
+    return this.userinfoService.updateinfo(req.user as number, data)
+  }
+  @Put('updateuserinfo')
+  @UseGuards(AuthGuard('jwt'))
+  updateuserinfo(@Req() req: Request, @Body() dto: userInfoDto) {
+    return this.userinfoService.updateuserinfo(req.user as number, dto)
+  }
+  @Get('count')
+  async count(@Query('id') id: number) {
+    return await this.userinfoService.count(+id)
+  }
+}

+ 9 - 0
src/userinfo/userinfo.module 2.ts

@@ -0,0 +1,9 @@
+import { Module } from '@nestjs/common';
+import { UserinfoService } from './userinfo.service';
+import { UserinfoController } from './userinfo.controller';
+
+@Module({
+  providers: [UserinfoService],
+  controllers: [UserinfoController]
+})
+export class UserinfoModule {}

+ 82 - 0
src/userinfo/userinfo.service 2.ts

@@ -0,0 +1,82 @@
+import { PrismaService } from '@/prisma/prisma.service'
+import { Injectable } from '@nestjs/common'
+import { auth } from '@prisma/client'
+import userDateDto from './dto/userinfo.dto'
+import userInfoDto from './dto/user.dto'
+
+@Injectable()
+export class UserinfoService {
+  constructor(private prisma: PrismaService) {}
+  async getinfo(id: number) {
+    const userinfo = await this.prisma.auth.findUnique({
+      where: {
+        auth_id: id,
+      },
+      include: {
+        user: true,
+      },
+    })
+    if (userinfo === null) {
+      return { cod: 400, msg: '用户不存在' }
+    }
+    delete userinfo.user.authId
+    delete userinfo.password
+    return { cod: 200, msg: '获取成功', data: { ...userinfo } }
+  }
+  async updateinfo(id: number, data: userDateDto) {
+    const userinfo = await this.prisma.auth.findUnique({
+      where: {
+        auth_id: id,
+      },
+      include: {
+        user: true,
+      },
+    })
+    const user = await this.prisma.userinfo.update({
+      where: {
+        authId: userinfo.user.authId,
+      },
+      data: {
+        avatar: data.avatar,
+        exp: data.exp,
+        level: data.level,
+      },
+    })
+    return { cod: 200, msg: '修改成功', data: user }
+  }
+  async updateuserinfo(id: number, dto: userInfoDto) {
+    const data = await this.prisma.userinfo.update({
+      where: {
+        authId: id,
+      },
+      data: {
+        QQ: dto.QQ,
+        nickname: dto.nickname,
+        github: dto.github,
+        signature: dto.signature,
+      },
+    })
+    return { cod: 200, msg: '修改成功', data }
+  }
+  async count(id: number) {
+    const mapleCoin = await this.prisma.userinfo.findUnique({
+      where: {
+        authId: id,
+      },
+      select: {
+        mapleCoin: true,
+      },
+    })
+    const post = await this.prisma.post.count({
+      where: {
+        authorId: id,
+      },
+    })
+    const reply = await this.prisma.comment.count({
+      where: {
+        authorId: id,
+      },
+    })
+    return { cod: 200, msg: '获取成功', data: { ...mapleCoin, post, reply } }
+  }
+}