-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Y-io
committed
Feb 19, 2019
1 parent
01fe4da
commit a089b84
Showing
31 changed files
with
406 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createParamDecorator } from '@nestjs/common'; | ||
|
||
export const User = createParamDecorator((data, req) => { | ||
return data ? req.user[data] : req.user; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +0,0 @@ | ||
// 状态 | ||
export enum StatusEnum { | ||
Examine = 'Examine', // 审核 | ||
Banned = 'Banned', // 禁止 | ||
Normal = 'Normal', // 正常 | ||
} | ||
|
||
// 权限列表 | ||
export enum RoleEnum { | ||
SuperAdmin = 'SuperAdmin', // 超级管理员 | ||
Admin = 'Admin', // 管理员 | ||
User = 'User', // 普通用户 | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
|
||
@Controller() | ||
export class CategoryController { | ||
// constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { Module, OnModuleInit } from '@nestjs/common'; | ||
import { CategoryResolver } from './category.resolver'; | ||
import { CategoryService } from './category.service'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { MongooseModule, InjectModel } from '@nestjs/mongoose'; | ||
import { CategorySchema } from './category.schema'; | ||
import { CategoryController } from './category.controller'; | ||
import { Model } from 'mongoose'; | ||
import { Category } from './category.interface'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([{ name: 'Category', schema: CategorySchema }]), | ||
], | ||
controllers: [], | ||
controllers: [CategoryController], | ||
providers: [CategoryResolver, CategoryService], | ||
}) | ||
export class CategoryModule {} | ||
export class CategoryModule implements OnModuleInit { | ||
constructor( | ||
@InjectModel('Category') private readonly categoryModel: Model<Category>, | ||
) {} | ||
async onModuleInit() { | ||
await this.createCategory(); | ||
} | ||
private async createCategory() { | ||
let category = await this.categoryModel.findOne({ name: '舞蹈' }); | ||
if (!category) { | ||
category = await this.categoryModel.create({ name: '舞蹈' }); | ||
await category.save(); | ||
|
||
category = await this.categoryModel.create({ name: '艺术体操' }); | ||
await category.save(); | ||
|
||
category = await this.categoryModel.create({ name: '美术' }); | ||
await category.save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Put, | ||
Query, | ||
Delete, | ||
Param, | ||
} from '@nestjs/common'; | ||
import { ICourseSupplier, CourseSupplier } from './course-supplier.interface'; | ||
import { Roles } from 'src/core'; | ||
import { RoleEnum } from '../base.object'; | ||
import { CourseSupplierService } from './course-supplier.service'; | ||
import { CommonResult } from '../base.interface'; | ||
import { User } from 'src/core/decorators/user.decorator'; | ||
import { User as IUer } from '../user/user.interface'; | ||
|
||
@Controller('courseSupplier') | ||
export class CourseSupplierController { | ||
constructor(private readonly courseSupplierService: CourseSupplierService) {} | ||
|
||
@Post() | ||
@Roles(RoleEnum.SuperAdmin, RoleEnum.Supplier) | ||
async createCourseSupplier( | ||
@User() user: IUer, | ||
@Body() body: ICourseSupplier, | ||
): Promise<CommonResult<CourseSupplier>> { | ||
const data = await this.courseSupplierService.createCourseSupplier( | ||
user, | ||
body, | ||
); | ||
return { code: 200, message: '创建成功', data }; | ||
} | ||
|
||
@Get() | ||
@Roles(RoleEnum.SuperAdmin, RoleEnum.Admin, RoleEnum.Supplier) | ||
async findCourseSupplier(): Promise<CommonResult<CourseSupplier[]>> { | ||
const data = await this.courseSupplierService.findCourseSupplier(); | ||
return { code: 200, message: '查询成功', data }; | ||
} | ||
|
||
@Put(':id') | ||
@Roles(RoleEnum.Supplier) | ||
async updataCourseSupplierById( | ||
@Param('id') id: string, | ||
@User() user: IUer, | ||
@Body() body: CourseSupplier, | ||
): Promise<CommonResult> { | ||
await this.courseSupplierService.updataCourseSupplierById(id, user, body); | ||
return { code: 200, message: '更新成功' }; | ||
} | ||
|
||
// @Delete(':id') | ||
// @Roles(RoleEnum.SuperAdmin, RoleEnum.Supplier) | ||
// async deleteCourseSupplierById( | ||
// @Param('id') id: string, | ||
// ): Promise<CommonResult> { | ||
// const; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { BaseInterface } from '../base.interface'; | ||
import { User } from '../user/user.interface'; | ||
import * as mongoose from 'mongoose'; | ||
|
||
export interface CourseSupplier extends BaseInterface { | ||
name: string; // 名称 | ||
status: string; // normal:正常, examine:审核, banned:禁止 | ||
content: string[]; // 文字内容 | ||
contentImage: string[]; // 图片内容 | ||
user: User; // 作者,关联用户文档 | ||
recycle: boolean; // 是否加入回收站 | ||
top: boolean; // 置顶 | ||
// comment: [ObjectId]; // 评论 | ||
minPeople: number; // 课程容纳最低人数 | ||
maxPeople: number; // 课程容纳最高人数 | ||
price: number; // 价格 | ||
discountPrice: number; // 零售的折扣价,用于业务员除外谈单 | ||
banner: [string]; // 海报列表 | ||
sex: number; // 0:不限, 1:男, 2:女 | ||
} | ||
|
||
export interface ICourseSupplier { | ||
_id: mongoose.Types.ObjectId; // id | ||
name: string; // 名称 | ||
sex: number; // 0:不限, 1:男, 2:女 | ||
minPeople: number; // 课程容纳最低人数 | ||
maxPeople: number; // 课程容纳最高人数 | ||
price: number; // 价格 | ||
banner: [string]; // 海报列表 | ||
content: string[]; // 文字内容 | ||
contentImage: string[]; // 图片内容 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { CourseSupplierController } from './course-supplier.controller'; | ||
import { CourseSupplierService } from './course-supplier.service'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { CourseSupplierSchema } from './course-supplier.schema'; | ||
import { UserSchema } from '../user/user.schema'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([ | ||
{ name: 'CourseSupplier', schema: CourseSupplierSchema }, | ||
{ name: 'User', schema: UserSchema }, | ||
]), | ||
], | ||
controllers: [CourseSupplierController], | ||
providers: [CourseSupplierService], | ||
}) | ||
export class CourseSupplierModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as mongoose from 'mongoose'; | ||
import { schemaOptions } from '../base.schema'; | ||
const { Schema } = mongoose; | ||
|
||
export const CourseSupplierSchema = new Schema( | ||
{ | ||
name: String, | ||
status: String, | ||
content: [String], // 文字内容 | ||
contentImage: [String], // 图片内容 | ||
user: { type: Schema.Types.ObjectId, ref: 'User' }, | ||
recycle: Boolean, | ||
top: Boolean, | ||
// comment: [ObjectId], | ||
minPeople: Number, | ||
maxPeople: Number, | ||
price: Number, | ||
discountPrice: Number, | ||
banner: [String], | ||
sex: Number, | ||
}, | ||
schemaOptions, | ||
); |
Oops, something went wrong.