Skip to content

Commit

Permalink
Implement Benefits Module (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 authored Oct 29, 2023
1 parent 9d0dbc3 commit c9c3446
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 7 deletions.
57 changes: 57 additions & 0 deletions src/popo/benefit/affiliate/affiliate.controller.ts
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);
}
}
5 changes: 5 additions & 0 deletions src/popo/benefit/affiliate/affiliate.dto.ts
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;
}
29 changes: 29 additions & 0 deletions src/popo/benefit/affiliate/affiliate.entity.ts
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;
}
15 changes: 15 additions & 0 deletions src/popo/benefit/affiliate/affiliate.module.ts
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 {}
34 changes: 34 additions & 0 deletions src/popo/benefit/affiliate/affiliate.service.ts
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 });
}
}
11 changes: 11 additions & 0 deletions src/popo/benefit/benefit.module.ts
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 {}
57 changes: 57 additions & 0 deletions src/popo/benefit/discount/discount.controller.ts
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);
}
}
7 changes: 7 additions & 0 deletions src/popo/benefit/discount/discount.dto.ts
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;
}
35 changes: 35 additions & 0 deletions src/popo/benefit/discount/discount.entity.ts
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;
}
15 changes: 15 additions & 0 deletions src/popo/benefit/discount/discount.module.ts
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 {}
34 changes: 34 additions & 0 deletions src/popo/benefit/discount/discount.service.ts
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 });
}
}
16 changes: 9 additions & 7 deletions src/popo/popo.module.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { Module } from '@nestjs/common';
import { UserModule } from './user/user.module';
import { PlaceModule } from './place/place.module';
import { BenefitModule } from './benefit/benefit.module';
import { EquipModule } from './equip/equip.module';
import { ReservationModule } from './reservation/reservation.module';
import { IntroduceModule } from './introduce/introduce.module';
import { WhitebookModule } from './whitebook/whitebook.module';
import { PlaceModule } from './place/place.module';
import { ReservationModule } from './reservation/reservation.module';
import { SettingModule } from './setting/setting.module';
import { UserModule } from './user/user.module';
import { WhitebookModule } from './whitebook/whitebook.module';

@Module({
imports: [
UserModule,
BenefitModule,
PlaceModule,
EquipModule,
ReservationModule,
IntroduceModule,
WhitebookModule,
ReservationModule,
SettingModule,
UserModule,
WhitebookModule,
],
controllers: [],
providers: [],
Expand Down

0 comments on commit c9c3446

Please sign in to comment.