-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
b02405d
commit 66cb3ad
Showing
11 changed files
with
526 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './page.dto'; |
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,66 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { replaceCharacterSlug } from '@rahino/commontools'; | ||
import { AutoMap } from 'automapper-classes'; | ||
import { Transform } from 'class-transformer'; | ||
import { | ||
IsNotEmpty, | ||
IsOptional, | ||
IsString, | ||
MaxLength, | ||
MinLength, | ||
} from 'class-validator'; | ||
|
||
export class PageDto { | ||
@MinLength(3) | ||
@MaxLength(256) | ||
@IsNotEmpty() | ||
@AutoMap() | ||
title: string; | ||
|
||
@Transform(({ value }) => replaceCharacterSlug(value)) | ||
@MinLength(3) | ||
@MaxLength(256) | ||
@IsNotEmpty() | ||
@AutoMap() | ||
slug: string; | ||
|
||
@AutoMap() | ||
@IsOptional() | ||
@IsString() | ||
@ApiProperty({ | ||
required: true, | ||
type: String, | ||
description: 'metaTitle', | ||
}) | ||
public metaTitle?: string; | ||
|
||
@AutoMap() | ||
@IsOptional() | ||
@IsString() | ||
@ApiProperty({ | ||
required: true, | ||
type: String, | ||
description: 'metaKeywords', | ||
}) | ||
public metaKeywords?: string; | ||
|
||
@AutoMap() | ||
@IsOptional() | ||
@IsString() | ||
@ApiProperty({ | ||
required: true, | ||
type: String, | ||
description: 'metaDescription', | ||
}) | ||
public metaDescription?: string; | ||
|
||
@AutoMap() | ||
@IsOptional() | ||
@IsString() | ||
@ApiProperty({ | ||
required: true, | ||
type: String, | ||
description: 'description', | ||
}) | ||
public description?: 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 @@ | ||
export * from './page.mapper'; |
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 { Injectable } from '@nestjs/common'; | ||
import { AutomapperProfile, InjectMapper } from 'automapper-nestjs'; | ||
import { PageDto } from '../dto'; | ||
import { Mapper, createMap, forMember, ignore } from 'automapper-core'; | ||
import { ECPage } from '@rahino/database/models/ecommerce-eav/ec-page.entity'; | ||
|
||
@Injectable() | ||
export class PageProfile extends AutomapperProfile { | ||
constructor(@InjectMapper() mapper: Mapper) { | ||
super(mapper); | ||
} | ||
|
||
override get profile() { | ||
return (mapper) => { | ||
createMap( | ||
mapper, | ||
PageDto, | ||
ECPage, | ||
forMember((dest) => dest.id, ignore()), | ||
); | ||
}; | ||
} | ||
} |
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,95 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
Param, | ||
Post, | ||
Put, | ||
Query, | ||
UseGuards, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { CheckPermission } from '@rahino/permission-checker/decorator'; | ||
import { PermissionGuard } from '@rahino/permission-checker/guard'; | ||
import { JsonResponseTransformInterceptor } from '@rahino/response/interceptor'; | ||
import { | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiQuery, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { JwtGuard } from '@rahino/auth/guard'; | ||
import { PageService } from './page.service'; | ||
import { PageDto } from './dto'; | ||
import { GetUser } from '@rahino/auth/decorator'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
|
||
@ApiTags('Admin-Pages') | ||
@UseGuards(JwtGuard, PermissionGuard) | ||
@ApiBearerAuth() | ||
@Controller({ | ||
path: '/api/ecommerce/pages', | ||
version: ['1'], | ||
}) | ||
export class PageController { | ||
constructor(private service: PageService) {} | ||
|
||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@CheckPermission({ permissionSymbol: 'ecommerce.admin.pages.getall' }) | ||
@ApiOperation({ description: 'show all pages' }) | ||
@Get('/') | ||
@ApiQuery({ | ||
name: 'filter', | ||
type: ListFilter, | ||
style: 'deepObject', | ||
explode: true, | ||
}) | ||
@HttpCode(HttpStatus.OK) | ||
async findAll(@Query() filter: ListFilter) { | ||
return await this.service.findAll(filter); | ||
} | ||
|
||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@ApiOperation({ description: 'show page by given id' }) | ||
@CheckPermission({ permissionSymbol: 'ecommerce.admin.pages.getone' }) | ||
@Get('/:id') | ||
@HttpCode(HttpStatus.OK) | ||
async findById(@Param('id') entityId: bigint) { | ||
return await this.service.findById(entityId); | ||
} | ||
|
||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@ApiOperation({ description: 'create page by admin' }) | ||
@CheckPermission({ permissionSymbol: 'ecommerce.admin.pages.create' }) | ||
@Post('/') | ||
@HttpCode(HttpStatus.CREATED) | ||
async create(@Body() dto: PageDto, @GetUser() user: User) { | ||
return await this.service.create(dto, user); | ||
} | ||
|
||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@ApiOperation({ description: 'update page by admin' }) | ||
@Put('/:id') | ||
@CheckPermission({ permissionSymbol: 'ecommerce.admin.pages.update' }) | ||
@HttpCode(HttpStatus.OK) | ||
async update( | ||
@Param('id') entityId: bigint, | ||
@Body() dto: PageDto, | ||
@GetUser() user: User, | ||
) { | ||
return await this.service.update(entityId, dto, user); | ||
} | ||
|
||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@ApiOperation({ description: 'delete page by admin' }) | ||
@Delete('/:id') | ||
@CheckPermission({ permissionSymbol: 'ecommerce.admin.pages.delete' }) | ||
@HttpCode(HttpStatus.OK) | ||
async deleteById(@Param('id') entityId: number) { | ||
return await this.service.deleteById(entityId); | ||
} | ||
} |
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,22 @@ | ||
import { | ||
MiddlewareConsumer, | ||
Module, | ||
NestModule, | ||
RequestMethod, | ||
} from '@nestjs/common'; | ||
import { PageController } from './page.controller'; | ||
import { PageService } from './page.service'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { Permission } from '@rahino/database/models/core/permission.entity'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { PageProfile } from './mapper'; | ||
import { ECPage } from '@rahino/database/models/ecommerce-eav/ec-page.entity'; | ||
|
||
@Module({ | ||
imports: [SequelizeModule.forFeature([User, Permission, ECPage])], | ||
controllers: [PageController], | ||
providers: [PageService, PageProfile], | ||
}) | ||
export class AdminPageModule implements NestModule { | ||
configure(consumer: MiddlewareConsumer) {} | ||
} |
Oops, something went wrong.