Skip to content

Commit

Permalink
Format only by prettier configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
khkim6040 committed Apr 15, 2024
1 parent 0bd2836 commit a2413c2
Show file tree
Hide file tree
Showing 41 changed files with 327 additions and 237 deletions.
2 changes: 1 addition & 1 deletion src/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Module } from '@nestjs/common';
import { AdminController } from './admin.controller';

@Module({
controllers: [AdminController]
controllers: [AdminController],
})
export class AdminModule {}
5 changes: 3 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config'
import { ConfigModule, ConfigService } from '@nestjs/config';

import { AppController } from './app.controller';
import { AppService } from './app.service';
Expand All @@ -18,7 +18,8 @@ import configuration from './config/configurations';
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => configService.get('database'),
useFactory: (configService: ConfigService) =>
configService.get('database'),
inject: [ConfigService],
}),
PopoModule,
Expand Down
8 changes: 6 additions & 2 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Injectable } from '@nestjs/common';
import * as moment from 'moment';
import * as momentTz from "moment-timezone";
import * as momentTz from 'moment-timezone';

@Injectable()
export class AppService {
getHello(): string {
return `Hello POPO! (popo-${process.env.POPO_VERSION}) (server now: ${moment().format('YYYY-MM-DD HH:mm:ss')}, KST now: ${momentTz().tz("Asia/Seoul").format('YYYY-MM-DD HH:mm:ss')})`;
return `Hello POPO! (popo-${
process.env.POPO_VERSION
}) (server now: ${moment().format(
'YYYY-MM-DD HH:mm:ss',
)}, KST now: ${momentTz().tz('Asia/Seoul').format('YYYY-MM-DD HH:mm:ss')})`;
}
}
39 changes: 25 additions & 14 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { MailService } from '../mail/mail.service';
import { ReservePlaceService } from '../popo/reservation/place/reserve.place.service';
import { ReserveEquipService } from '../popo/reservation/equip/reserve.equip.service';
import { ApiTags } from '@nestjs/swagger';
import {JwtPayload} from "./strategies/jwt.payload";
import {PasswordResetRequest, PasswordUpdateRequest} from "./auth.dto";
import { JwtPayload } from './strategies/jwt.payload';
import { PasswordResetRequest, PasswordUpdateRequest } from './auth.dto';

const requiredRoles = [UserType.admin, UserType.association, UserType.staff];

Expand Down Expand Up @@ -95,7 +95,7 @@ export class AuthController {
// update Login History
const existUser = await this.userService.findOneByUuidOrFail(user.uuid);
await this.userService.updateLogin(existUser.uuid);

return res.send(user);
}

Expand All @@ -115,8 +115,8 @@ export class AuthController {

try {
await this.mailService.sendVerificationMail(
createUserDto.email,
saveUser.uuid,
createUserDto.email,
saveUser.uuid,
);
} catch (error) {
console.log('!! 유저 인증 메일 전송 실패 !!');
Expand All @@ -133,25 +133,36 @@ export class AuthController {
}

@Post('password/reset')
async resetPassword(
@Body() body: PasswordResetRequest,
) {
async resetPassword(@Body() body: PasswordResetRequest) {
const existUser = await this.userService.findOneByEmail(body.email);

if (!existUser) {
throw new BadRequestException('해당 이메일로 가입한 유저가 존재하지 않습니다.');
throw new BadRequestException(
'해당 이메일로 가입한 유저가 존재하지 않습니다.',
);
}

if (existUser.userStatus === UserStatus.password_reset) {
throw new BadRequestException('이미 비빌번호를 초기화 했습니다. 신규 비밀번호를 메일에서 확인해주세요.');
throw new BadRequestException(
'이미 비빌번호를 초기화 했습니다. 신규 비밀번호를 메일에서 확인해주세요.',
);
}

// generate 8-length random password
const temp_password = 'poapper_' + Math.random().toString(36).slice(-8);

await this.userService.updatePasswordByEmail(existUser.email, temp_password);
await this.userService.updateUserStatus(existUser.uuid, UserStatus.password_reset);
await this.mailService.sendPasswordResetMail(existUser.email, temp_password);
await this.userService.updatePasswordByEmail(
existUser.email,
temp_password,
);
await this.userService.updateUserStatus(
existUser.uuid,
UserStatus.password_reset,
);
await this.mailService.sendPasswordResetMail(
existUser.email,
temp_password,
);
}

@Post('password/update')
Expand Down
29 changes: 14 additions & 15 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {Module} from '@nestjs/common';
import {JwtModule} from '@nestjs/jwt';
import {PassportModule} from '@nestjs/passport';
import {AuthService} from './auth.service';
import {jwtConstants} from './constants';
import {JwtStrategy} from './strategies/jwt.strategy';
import {LocalStrategy} from './strategies/local.strategy';
import {UserModule} from "../popo/user/user.module";
import {AuthController} from './auth.controller';
import {MailModule} from "../mail/mail.module";
import {ReservePlaceModule} from "../popo/reservation/place/reserve.place.module";
import { ReserveEquipModule } from "../popo/reservation/equip/reserve.equip.module";
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { AuthService } from './auth.service';
import { jwtConstants } from './constants';
import { JwtStrategy } from './strategies/jwt.strategy';
import { LocalStrategy } from './strategies/local.strategy';
import { UserModule } from '../popo/user/user.module';
import { AuthController } from './auth.controller';
import { MailModule } from '../mail/mail.module';
import { ReservePlaceModule } from '../popo/reservation/place/reserve.place.module';
import { ReserveEquipModule } from '../popo/reservation/equip/reserve.equip.module';

@Module({
imports: [
Expand All @@ -20,12 +20,11 @@ import { ReserveEquipModule } from "../popo/reservation/equip/reserve.equip.modu
PassportModule,
JwtModule.register({
secret: jwtConstants.secret,
signOptions: {expiresIn: '360000s'},
signOptions: { expiresIn: '360000s' },
}),
],
providers: [AuthService, LocalStrategy, JwtStrategy],
exports: [AuthService],
controllers: [AuthController],
})
export class AuthModule {
}
export class AuthModule {}
4 changes: 1 addition & 3 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AuthService {
}

const cryptoSalt = user.cryptoSalt;

if (user.userStatus == UserStatus.password_reset) {
await this.usersService.updateUserStatus(user.uuid, UserStatus.activated);
} else if (user.userStatus != UserStatus.activated) {
Expand All @@ -39,8 +39,6 @@ export class AuthService {
}
}



async generateJwtToken(user: any) {
const payload = {
uuid: user.uuid,
Expand Down
6 changes: 3 additions & 3 deletions src/auth/authroization/roles.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SetMetadata} from "@nestjs/common";
import {UserType} from "../../popo/user/user.meta";
import { SetMetadata } from '@nestjs/common';
import { UserType } from '../../popo/user/user.meta';

export const Roles = (...roles: UserType[]) => SetMetadata('roles', roles);
export const Roles = (...roles: UserType[]) => SetMetadata('roles', roles);
16 changes: 8 additions & 8 deletions src/auth/authroization/roles.guard.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {CanActivate, ExecutionContext, Injectable} from "@nestjs/common";
import {Reflector} from '@nestjs/core';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';

@Injectable()
export class RolesGuard implements CanActivate {
constructor(
private readonly reflector: Reflector
) {
}
constructor(private readonly reflector: Reflector) {}

canActivate(context: ExecutionContext): boolean {
const requiredRoles = this.reflector.get<string[]>('roles', context.getHandler());
const requiredRoles = this.reflector.get<string[]>(
'roles',
context.getHandler(),
);
// 모든 Role에서 접근 가능
if (!requiredRoles) {
return true;
Expand All @@ -20,4 +20,4 @@ export class RolesGuard implements CanActivate {

return requiredRoles.some((role) => user.userType?.includes(role));
}
}
}
10 changes: 5 additions & 5 deletions src/auth/strategies/local.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Injectable, UnauthorizedException} from '@nestjs/common';
import {PassportStrategy} from '@nestjs/passport';
import {Strategy} from 'passport-local';
import {AuthService} from '../auth.service';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-local';
import { AuthService } from '../auth.service';

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super({usernameField: 'email'});
super({ usernameField: 'email' });
}

async validate(email: string, password: string): Promise<any> {
Expand Down
14 changes: 6 additions & 8 deletions src/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export class FileService {

constructor() {}



async queryOnS3(key: string, query: string) {
const res = await this.s3.send(
new SelectObjectContentCommand({
Expand All @@ -30,19 +28,19 @@ export class FileService {
Expression: query,
InputSerialization: {
CSV: {
FileHeaderInfo: "USE",
FileHeaderInfo: 'USE',
},
},
OutputSerialization: {
JSON: {
RecordDelimiter: ',',
},
},
})
)
}),
);

if (!res.Payload) {
throw new Error("No payload received from S3 SelectObjectContent");
throw new Error('No payload received from S3 SelectObjectContent');
}

const convertDataToJson = async (generator) => {
Expand All @@ -65,8 +63,8 @@ export class FileService {
new GetObjectCommand({
Bucket: this.bucket,
Key: key,
})
)
}),
);
return res.Body.transformToString();
}

Expand Down
8 changes: 4 additions & 4 deletions src/mail/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ export class MailService {
<p>장비 ${equipments
.map((equip) => equip.name)
.join(', ')}에 대한 예약 "<strong>${reservation.title}</strong>"(${
reservation.date
} - ${reservation.start_time} ~ ${
reservation.end_time
})이/가 생성 되었습니다.</p>
reservation.date
} - ${reservation.start_time} ~ ${
reservation.end_time
})이/가 생성 되었습니다.</p>
<p>장비 예약 담당자 님은 예약을 확인하고 처리해주세요 🙏</p>
</body>
</html>`,
Expand Down
4 changes: 1 addition & 3 deletions src/popo/benefit/affiliate/affiliate.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { AffiliateController } from './affiliate.controller';
import { AffiliateService } from './affiliate.service';

@Module({
imports: [
TypeOrmModule.forFeature([Affiliate]),
],
imports: [TypeOrmModule.forFeature([Affiliate])],
providers: [AffiliateService],
controllers: [AffiliateController],
})
Expand Down
2 changes: 1 addition & 1 deletion src/popo/benefit/affiliate/affiliate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AffiliateService {
}

findById(id: number) {
return this.affiliateRepo.findOneBy({id: id });
return this.affiliateRepo.findOneBy({ id: id });
}

update(id: number, dto: AffiliateDto) {
Expand Down
5 changes: 1 addition & 4 deletions src/popo/benefit/benefit.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { AffiliateModule } from './affiliate/affiliate.module';
import { DiscountModule } from './discount/discount.module';

@Module({
imports: [
AffiliateModule,
DiscountModule,
]
imports: [AffiliateModule, DiscountModule],
})
export class BenefitModule {}
4 changes: 1 addition & 3 deletions src/popo/benefit/discount/discount.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { DiscountController } from './discount.controller';
import { DiscountService } from './discount.service';

@Module({
imports: [
TypeOrmModule.forFeature([Discount]),
],
imports: [TypeOrmModule.forFeature([Discount])],
providers: [DiscountService],
controllers: [DiscountController],
})
Expand Down
2 changes: 1 addition & 1 deletion src/popo/benefit/discount/discount.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class DiscountService {
}

findById(id: number) {
return this.discountRepo.findOneBy({id: id });
return this.discountRepo.findOneBy({ id: id });
}

update(id: number, dto: DiscountDto) {
Expand Down
2 changes: 1 addition & 1 deletion src/popo/equip/equip.meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export enum EquipOwner {
dormUnion = 'dormUnion',
saengna = 'saengna',
others = 'others',
}
}
10 changes: 7 additions & 3 deletions src/popo/introduce/association/intro.association.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ export class IntroAssociationController {
getTodayVisited() {
return this.introAssociationService.find({
where: {
updateAt: Between(moment().startOf('day').toDate(), moment().endOf('day').toDate()),
}
updateAt: Between(
moment().startOf('day').toDate(),
moment().endOf('day').toDate(),
),
},
});
}

@Get('name/:name')
async getOneByName(@Param('name') name: string) {
const introAssociation = await this.introAssociationService.findOneByName(name);
const introAssociation =
await this.introAssociationService.findOneByName(name);

if (introAssociation) {
await this.introAssociationService.updateViewCount(
Expand Down
6 changes: 3 additions & 3 deletions src/popo/introduce/association/intro.association.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export class IntroAssociationService {
}

findOneByUuid(uuid: string) {
return this.introAssociation_repository.findOneBy({ uuid: uuid});
return this.introAssociation_repository.findOneBy({ uuid: uuid });
}

findOneByUuidOrFail(uuid: string) {
return this.introAssociation_repository.findOneByOrFail({ uuid: uuid});
return this.introAssociation_repository.findOneByOrFail({ uuid: uuid });
}

findOneByName(name: string) {
return this.introAssociation_repository.findOneBy({ name: name});
return this.introAssociation_repository.findOneBy({ name: name });
}

async update(uuid: string, dto: CreateIntroAssociationDto) {
Expand Down
Loading

0 comments on commit a2413c2

Please sign in to comment.