初始化:职引项目 v1.0
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { Controller, Post, Get, Delete, Param, Body } from '@nestjs/common'
|
||||
import { ResumeService } from './resume.service'
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator'
|
||||
|
||||
@Controller('resume')
|
||||
export class ResumeController {
|
||||
constructor(private resumeService: ResumeService) {}
|
||||
|
||||
@Post('create')
|
||||
async create(
|
||||
@CurrentUser('userId') userId: string,
|
||||
@Body('title') title: string,
|
||||
@Body('content') content: string,
|
||||
@Body('targetPosition') targetPosition?: string,
|
||||
) {
|
||||
return this.resumeService.create(userId, title, content, targetPosition)
|
||||
}
|
||||
|
||||
@Get('list')
|
||||
async list(@CurrentUser('userId') userId: string) {
|
||||
return this.resumeService.list(userId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async getDetail(@Param('id') id: string, @CurrentUser('userId') userId: string) {
|
||||
return this.resumeService.getDetail(id, userId)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param('id') id: string, @CurrentUser('userId') userId: string) {
|
||||
return this.resumeService.delete(id, userId)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { MongooseModule } from '@nestjs/mongoose'
|
||||
import { ResumeController } from './resume.controller'
|
||||
import { ResumeService } from './resume.service'
|
||||
import { Resume, ResumeSchema } from './resume.schema'
|
||||
|
||||
@Module({
|
||||
imports: [MongooseModule.forFeature([{ name: Resume.name, schema: ResumeSchema }])],
|
||||
controllers: [ResumeController],
|
||||
providers: [ResumeService],
|
||||
})
|
||||
export class ResumeModule {}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
|
||||
import { Document, Types } from 'mongoose'
|
||||
|
||||
export type ResumeDocument = Resume & Document
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class Resume {
|
||||
@Prop({ type: Types.ObjectId, ref: 'User', required: true })
|
||||
userId: Types.ObjectId
|
||||
|
||||
@Prop({ required: true })
|
||||
title: string
|
||||
|
||||
@Prop({ default: '' })
|
||||
content: string
|
||||
|
||||
@Prop({ default: '' })
|
||||
targetPosition: string
|
||||
}
|
||||
|
||||
export const ResumeSchema = SchemaFactory.createForClass(Resume)
|
||||
ResumeSchema.index({ userId: 1, createdAt: -1 })
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Injectable, HttpException, HttpStatus } from '@nestjs/common'
|
||||
import { InjectModel } from '@nestjs/mongoose'
|
||||
import { Model } from 'mongoose'
|
||||
import { Resume, ResumeDocument } from './resume.schema'
|
||||
|
||||
@Injectable()
|
||||
export class ResumeService {
|
||||
constructor(@InjectModel(Resume.name) private resumeModel: Model<ResumeDocument>) {}
|
||||
|
||||
async create(userId: string, title: string, content: string, targetPosition?: string) {
|
||||
const resume = await this.resumeModel.create({ userId, title, content, targetPosition })
|
||||
return resume.toObject()
|
||||
}
|
||||
|
||||
async list(userId: string) {
|
||||
const list = await this.resumeModel.find({ userId }).sort({ createdAt: -1 }).exec()
|
||||
return list.map(r => ({
|
||||
id: r._id.toString(),
|
||||
title: r.title,
|
||||
targetPosition: r.targetPosition,
|
||||
createdAt: (r as any).createdAt,
|
||||
}))
|
||||
}
|
||||
|
||||
async getDetail(resumeId: string, userId: string) {
|
||||
const resume = await this.resumeModel.findOne({ _id: resumeId, userId }).exec()
|
||||
if (!resume) throw new HttpException('简历不存在', HttpStatus.NOT_FOUND)
|
||||
return resume.toObject()
|
||||
}
|
||||
|
||||
async delete(resumeId: string, userId: string) {
|
||||
const res = await this.resumeModel.deleteOne({ _id: resumeId, userId }).exec()
|
||||
if (res.deletedCount === 0) throw new HttpException('简历不存在', HttpStatus.NOT_FOUND)
|
||||
return { message: '删除成功' }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user