-
Notifications
You must be signed in to change notification settings - Fork 58
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
Showing
22 changed files
with
633 additions
and
535 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
7 changes: 0 additions & 7 deletions
7
packages/_leaa-common/src/dtos/category/update-category.input.ts
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,27 +1,20 @@ | ||
import { IsOptional } from 'class-validator'; | ||
import { Field, InputType, Int } from '@nestjs/graphql'; | ||
|
||
import { Category } from '@leaa/common/src/entrys'; | ||
|
||
@InputType() | ||
export class UpdateCategoryInput { | ||
@IsOptional() | ||
@Field(() => String) | ||
name?: string; | ||
|
||
@IsOptional() | ||
@Field(() => String) | ||
slug?: string; | ||
|
||
@IsOptional() | ||
@Field(() => String, { nullable: true }) | ||
parent_id?: string | null; | ||
|
||
@IsOptional() | ||
@Field(() => String, { nullable: true }) | ||
description?: string; | ||
|
||
// @IsOptional() | ||
// @Field(() => Category, { nullable: true }) | ||
parent?: Category | null; | ||
} |
15 changes: 8 additions & 7 deletions
15
packages/_leaa-common/src/dtos/setting/update-settings.input.ts
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 +1,14 @@ | ||
import { IsNotEmpty } from 'class-validator'; | ||
import { Field, InputType } from '@nestjs/graphql'; | ||
|
||
@InputType() | ||
export class UpdateSettingsInput { | ||
@IsNotEmpty() | ||
@Field(() => String) | ||
id!: string; | ||
settings!: { | ||
id: string; | ||
value: string; | ||
}[]; | ||
|
||
@IsNotEmpty() | ||
@Field(() => String) | ||
value!: string; | ||
// id!: string; | ||
// | ||
// @IsNotEmpty() | ||
// value!: 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 |
---|---|---|
@@ -1,25 +1,21 @@ | ||
import { PrimaryGeneratedColumn, Column } from 'typeorm'; | ||
import { ObjectType, Field, Int } from '@nestjs/graphql'; | ||
import { Exclude } from 'class-transformer'; | ||
|
||
@ObjectType() | ||
export class Base { | ||
@PrimaryGeneratedColumn('uuid') | ||
@Field(() => String) | ||
id!: string; | ||
|
||
// | ||
|
||
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) | ||
@Field(() => Date) | ||
created_at!: Date; | ||
|
||
@Column({ type: 'timestamp', nullable: true, onUpdate: 'CURRENT_TIMESTAMP' }) | ||
@Field(() => Date, { nullable: true }) | ||
updated_at?: Date; | ||
|
||
// SOFT DELETE | ||
// https://github.com/typeorm/typeorm/issues/534 | ||
@Exclude({ toPlainOnly: true }) | ||
@Column({ type: 'timestamp', nullable: true }) | ||
@Field(() => Date, { nullable: true }) | ||
deleted_at?: Date; | ||
} |
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,40 +1,31 @@ | ||
import { ObjectType, Field } from '@nestjs/graphql'; | ||
|
||
import { Index, Entity, Tree, Column, TreeChildren, TreeParent } from 'typeorm'; | ||
|
||
import { Base } from '@leaa/common/src/entrys'; | ||
|
||
@Entity('categories') | ||
@Index('categories_name_unique', ['name'], { unique: true }) | ||
@Index('categories_slug_unique', ['slug'], { unique: true }) | ||
@ObjectType() | ||
@Tree('nested-set') | ||
export class Category extends Base { | ||
@Column({ type: 'varchar', length: 32, unique: true }) | ||
@Field(() => String, { nullable: true }) | ||
@Column({ type: 'varchar', length: 64, unique: true }) | ||
name!: string | null; | ||
|
||
@Column({ type: 'varchar', length: 32, unique: true }) | ||
@Field(() => String) | ||
// @Index() | ||
@Column({ type: 'varchar', length: 64, unique: true }) | ||
slug!: string; | ||
|
||
@Column({ type: 'varchar', nullable: true }) | ||
@Field(() => String, { nullable: true }) | ||
parent_id!: string | null; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
@Field(() => String, { nullable: true }) | ||
description?: string | null; | ||
|
||
@TreeChildren() | ||
@Field(() => [Category], { nullable: true }) | ||
children?: Category[] | null; | ||
|
||
@TreeParent() | ||
@Field(() => Category, { nullable: true }) | ||
parent?: Category | null; | ||
|
||
// Virtual Field (not in DB) | ||
// @Field(() => String, { nullable: true }) | ||
// key?: string | null; | ||
} |
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,42 +1,31 @@ | ||
import { Index, Entity, Column } from 'typeorm'; | ||
import { ObjectType, Field, Int } from '@nestjs/graphql'; | ||
|
||
import { Base } from '@leaa/common/src/entrys'; | ||
|
||
@Entity('settings') | ||
@Index('settings_name_unique', ['name'], { unique: true }) | ||
@Index('settings_slug_unique', ['slug'], { unique: true }) | ||
@ObjectType() | ||
export class Setting extends Base { | ||
@Column({ type: 'varchar', length: 32, unique: true }) | ||
@Field(() => String) | ||
name!: string; | ||
|
||
@Column({ type: 'varchar', length: 32, unique: true }) | ||
@Field(() => String, { nullable: true }) | ||
slug?: string; | ||
|
||
@Column({ type: 'varchar', length: 32 }) | ||
@Field(() => String, { nullable: true }) | ||
type!: string; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
@Field(() => String, { nullable: true }) | ||
description?: string; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
@Field(() => String, { nullable: true }) | ||
options?: string; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
@Field(() => String, { nullable: true }) | ||
value?: string; | ||
|
||
@Column({ type: 'int', default: 0 }) | ||
@Field(() => Int) | ||
sort!: number; | ||
|
||
@Column({ type: 'int', default: 0 }) | ||
@Field(() => Int) | ||
private!: number; | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
packages/leaa-api/src/modules/setting/setting.controller.ts
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,63 @@ | ||
import { Controller, UseGuards, Get, Put, Post, Body } from '@nestjs/common'; | ||
import { Crud, CrudController, Override, ParsedRequest, ParsedBody, CrudRequest } from '@nestjsx/crud'; | ||
|
||
import { Permissions } from '@leaa/api/src/decorators'; | ||
import { CreateSettingInput, UpdateSettingInput, UpdateSettingsInput } from '@leaa/common/src/dtos/setting'; | ||
import { JwtGuard, PermissionsGuard } from '@leaa/api/src/guards'; | ||
import { Setting } from '@leaa/common/src/entrys'; | ||
|
||
import { SettingService } from './setting.service'; | ||
|
||
@Crud({ | ||
model: { type: Setting }, | ||
params: { | ||
id: { | ||
field: 'id', | ||
type: 'uuid', | ||
primary: true, | ||
}, | ||
}, | ||
query: { | ||
maxLimit: 1000, | ||
alwaysPaginate: true, | ||
sort: [{ field: 'sort', order: 'ASC' }], | ||
// join: { | ||
// tags: { eager: true }, | ||
// categories: { eager: true }, | ||
// }, | ||
}, | ||
routes: { | ||
// getManyBase: { decorators: [Permissions('setting.list-read')] }, | ||
// getOneBase: { decorators: [Permissions('setting.item-read')] }, | ||
createOneBase: { decorators: [UseGuards(JwtGuard, PermissionsGuard), Permissions('setting.item-create')] }, | ||
updateOneBase: { decorators: [UseGuards(JwtGuard, PermissionsGuard), Permissions('setting.item-update')] }, | ||
deleteOneBase: { | ||
decorators: [UseGuards(JwtGuard, PermissionsGuard), Permissions('setting.item-delete')], | ||
returnDeleted: true, | ||
}, | ||
}, | ||
dto: { | ||
create: CreateSettingInput, | ||
update: UpdateSettingInput, | ||
}, | ||
}) | ||
@Controller('/settings') | ||
export class SettingController implements CrudController<Setting> { | ||
constructor(public service: SettingService) {} | ||
|
||
@Override('updateOneBase') | ||
@UseGuards(JwtGuard, PermissionsGuard) | ||
@Permissions('setting.item-update') | ||
updateOne(@ParsedRequest() req: CrudRequest, @ParsedBody() dto: UpdateSettingInput): Promise<Setting> { | ||
return this.service.updateOne(req, dto); | ||
} | ||
|
||
// | ||
|
||
@Post('batch') | ||
@UseGuards(JwtGuard, PermissionsGuard) | ||
@Permissions('setting.item-update') | ||
batchUpdate(@Body() dto: UpdateSettingsInput): Promise<Setting[]> { | ||
return this.service.batchUpdate(dto); | ||
} | ||
} |
Oops, something went wrong.