-
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
1 parent
9d0dbc3
commit c9c3446
Showing
12 changed files
with
308 additions
and
7 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,57 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
Post, | ||
Put, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { ApiBody, ApiTags } from '@nestjs/swagger'; | ||
|
||
import { AffiliateService } from './affiliate.service'; | ||
import { AffiliateDto } from './affiliate.dto'; | ||
import { Roles } from 'src/auth/authroization/roles.decorator'; | ||
import { RolesGuard } from 'src/auth/authroization/roles.guard'; | ||
import { UserType } from 'src/popo/user/user.meta'; | ||
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; | ||
|
||
@ApiTags('Benefit/Affiliate') | ||
@Controller('benefit/affiliate') | ||
export class AffiliateController { | ||
constructor(private readonly affiliateService: AffiliateService) {} | ||
|
||
@Post() | ||
@Roles(UserType.admin, UserType.association) | ||
@UseGuards(JwtAuthGuard, RolesGuard) | ||
@ApiBody({ type: AffiliateDto }) | ||
createAffiliate(@Body() dto: AffiliateDto) { | ||
return this.affiliateService.save(dto); | ||
} | ||
|
||
@Get() | ||
getAllAffiliates() { | ||
return this.affiliateService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
getAffiliateByUuid(@Param('id') id: number) { | ||
return this.affiliateService.findById(id); | ||
} | ||
|
||
@Put(':id') | ||
@Roles(UserType.admin, UserType.association) | ||
@UseGuards(JwtAuthGuard, RolesGuard) | ||
@ApiBody({ type: AffiliateDto }) | ||
updateAffiliate(@Param('id') id: number, @Body() dto: AffiliateDto) { | ||
return this.affiliateService.update(id, dto); | ||
} | ||
|
||
@Delete(':id') | ||
@Roles(UserType.admin, UserType.association) | ||
@UseGuards(JwtAuthGuard, RolesGuard) | ||
deleteAffiliate(@Param('id') id: number) { | ||
return this.affiliateService.delete(id); | ||
} | ||
} |
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 @@ | ||
export class AffiliateDto { | ||
readonly title: string; | ||
readonly content_short: string; | ||
readonly content: 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,29 @@ | ||
import { | ||
BaseEntity, | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
|
||
@Entity() | ||
export class Affiliate extends BaseEntity { | ||
@PrimaryGeneratedColumn('increment') | ||
id: number; | ||
|
||
@Column({ nullable: false }) | ||
title: string; | ||
|
||
@Column('text', { nullable: true }) | ||
content_short: string; | ||
|
||
@Column('text', { nullable: false }) | ||
content: string; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
|
||
@UpdateDateColumn() | ||
updateAt: 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
import { Affiliate } from './affiliate.entity'; | ||
import { AffiliateController } from './affiliate.controller'; | ||
import { AffiliateService } from './affiliate.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forFeature([Affiliate]), | ||
], | ||
providers: [AffiliateService], | ||
controllers: [AffiliateController], | ||
}) | ||
export class AffiliateModule {} |
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,34 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { Affiliate } from './affiliate.entity'; | ||
import { AffiliateDto } from './affiliate.dto'; | ||
|
||
@Injectable() | ||
export class AffiliateService { | ||
constructor( | ||
@InjectRepository(Affiliate) | ||
private readonly affiliateRepo: Repository<Affiliate>, | ||
) {} | ||
|
||
save(dto: AffiliateDto) { | ||
return this.affiliateRepo.save(dto); | ||
} | ||
|
||
findAll() { | ||
return this.affiliateRepo.find(); | ||
} | ||
|
||
findById(id: number) { | ||
return this.affiliateRepo.findOneBy({id: id }); | ||
} | ||
|
||
update(id: number, dto: AffiliateDto) { | ||
return this.affiliateRepo.update({ id: id }, dto); | ||
} | ||
|
||
delete(id: number) { | ||
return this.affiliateRepo.delete({ id: id }); | ||
} | ||
} |
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,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AffiliateModule } from './affiliate/affiliate.module'; | ||
import { DiscountModule } from './discount/discount.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
AffiliateModule, | ||
DiscountModule, | ||
] | ||
}) | ||
export class BenefitModule {} |
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,57 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
Post, | ||
Put, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { ApiBody, ApiTags } from '@nestjs/swagger'; | ||
|
||
import { DiscountService } from './discount.service'; | ||
import { DiscountDto } from './discount.dto'; | ||
import { Roles } from 'src/auth/authroization/roles.decorator'; | ||
import { RolesGuard } from 'src/auth/authroization/roles.guard'; | ||
import { UserType } from 'src/popo/user/user.meta'; | ||
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; | ||
|
||
@ApiTags('Benefit/Discount') | ||
@Controller('benefit/discount') | ||
export class DiscountController { | ||
constructor(private readonly discountService: DiscountService) {} | ||
|
||
@Post() | ||
@Roles(UserType.admin, UserType.association) | ||
@UseGuards(JwtAuthGuard, RolesGuard) | ||
@ApiBody({ type: DiscountDto }) | ||
createDiscount(@Body() dto: DiscountDto) { | ||
return this.discountService.save(dto); | ||
} | ||
|
||
@Get() | ||
getAllDiscounts() { | ||
return this.discountService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
getDiscountByUuid(@Param('id') id: number) { | ||
return this.discountService.findById(id); | ||
} | ||
|
||
@Put(':id') | ||
@Roles(UserType.admin, UserType.association) | ||
@UseGuards(JwtAuthGuard, RolesGuard) | ||
@ApiBody({ type: DiscountDto }) | ||
updateDiscount(@Param('id') id: number, @Body() dto: DiscountDto) { | ||
return this.discountService.update(id, dto); | ||
} | ||
|
||
@Delete(':id') | ||
@Roles(UserType.admin, UserType.association) | ||
@UseGuards(JwtAuthGuard, RolesGuard) | ||
deleteDiscount(@Param('id') id: number) { | ||
return this.discountService.delete(id); | ||
} | ||
} |
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,7 @@ | ||
export class DiscountDto { | ||
readonly title: string; | ||
readonly region: string; | ||
readonly open_hour: string; | ||
readonly phone: string; | ||
readonly content: 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,35 @@ | ||
import { | ||
BaseEntity, | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
|
||
@Entity() | ||
export class Discount extends BaseEntity { | ||
@PrimaryGeneratedColumn('increment') | ||
id: number; | ||
|
||
@Column({ nullable: false }) | ||
title: string; | ||
|
||
@Column({ nullable: true }) | ||
region: string; | ||
|
||
@Column({ nullable: true }) | ||
open_hour: string; | ||
|
||
@Column({ nullable: true }) | ||
phone: string; | ||
|
||
@Column('text', { nullable: false }) | ||
content: string; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
|
||
@UpdateDateColumn() | ||
updateAt: 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
import { Discount } from './discount.entity'; | ||
import { DiscountController } from './discount.controller'; | ||
import { DiscountService } from './discount.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forFeature([Discount]), | ||
], | ||
providers: [DiscountService], | ||
controllers: [DiscountController], | ||
}) | ||
export class DiscountModule {} |
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,34 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { Discount } from './discount.entity'; | ||
import { DiscountDto } from './discount.dto'; | ||
|
||
@Injectable() | ||
export class DiscountService { | ||
constructor( | ||
@InjectRepository(Discount) | ||
private readonly discountRepo: Repository<Discount>, | ||
) {} | ||
|
||
save(dto: DiscountDto) { | ||
return this.discountRepo.save(dto); | ||
} | ||
|
||
findAll() { | ||
return this.discountRepo.find(); | ||
} | ||
|
||
findById(id: number) { | ||
return this.discountRepo.findOneBy({id: id }); | ||
} | ||
|
||
update(id: number, dto: DiscountDto) { | ||
return this.discountRepo.update({ id: id }, dto); | ||
} | ||
|
||
delete(id: number) { | ||
return this.discountRepo.delete({ id: id }); | ||
} | ||
} |
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