Skip to content

Commit

Permalink
Adapt to crawler
Browse files Browse the repository at this point in the history
  • Loading branch information
gyusang committed Sep 29, 2024
1 parent 1eddb93 commit 19a9895
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
npm test
prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown
git update-index --again
prettier `git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g'` --write --ignore-unknown
git update-index --again
3 changes: 1 addition & 2 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcrypt';

import { User } from '../user/user.entity.js';
import { Payload } from '../types/custom-type';
import { User } from '../user/user.entity';

@Injectable()
export class AuthService {
Expand Down
2 changes: 1 addition & 1 deletion src/auth/jwt-access.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';

import { User } from '../user/user.entity.js';
import { Payload } from '../types/custom-type';
import { User } from '../user/user.entity';

@Injectable()
export class JwtAccessStrategy extends PassportStrategy(Strategy, 'jwt-access') {
Expand Down
4 changes: 2 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataSource } from 'typeorm';
import { DataSource, DataSourceOptions } from 'typeorm';

import * as dataSourceOptions from './ormconfig.js';

export const dataSource = new DataSource(dataSourceOptions);
export const dataSource = new DataSource(dataSourceOptions as DataSourceOptions);
25 changes: 13 additions & 12 deletions src/department/department.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
OneToMany,
PrimaryGeneratedColumn,
RelationId,
Relation,
} from 'typeorm';

import { Notice } from '../notice/notice.entity';
import { User } from '../user/user.entity';
import { Notice } from '../notice/notice.entity.js';
import { User } from '../user/user.entity.js';

@Entity()
export class Department extends BaseEntity {
Expand All @@ -26,14 +27,14 @@ export class Department extends BaseEntity {
college!: string;

@OneToMany(() => Notice, (notice) => notice.department)
notices!: Notice[];
notices!: Relation<Notice[]>;

@Transform((tags) => [...new Set(tags.value.map((tag: Tag) => tag.name))])
@OneToMany(() => Tag, (tag) => tag.department)
tags!: Tag[];
tags!: Relation<Tag[]>;

@Transform((tags) => tags.value.map((tag: Tag) => tag.name))
follow?: Tag[];
follow?: Relation<Tag[]>;

@Column()
link!: string;
Expand All @@ -59,13 +60,13 @@ export class Tag extends BaseEntity {
nullable: false,
onDelete: 'CASCADE',
})
department!: Department;
department!: Relation<Department>;

@OneToMany(() => UserTag, (userTag) => userTag.tag)
userTags!: UserTag[];
userTags!: Relation<UserTag[]>;

@OneToMany(() => NoticeTag, (noticeTag) => noticeTag.tag)
noticeTags!: NoticeTag[];
noticeTags!: Relation<NoticeTag[]>;
}

@Entity()
Expand All @@ -77,13 +78,13 @@ export class UserTag extends BaseEntity {
nullable: false,
onDelete: 'CASCADE',
})
user!: User;
user!: Relation<User>;

@ManyToOne(() => Tag, (tag) => tag.userTags, {
nullable: false,
onDelete: 'CASCADE',
})
tag!: Tag;
tag!: Relation<Tag>;
}

@Entity()
Expand All @@ -96,13 +97,13 @@ export class NoticeTag extends BaseEntity {
nullable: false,
onDelete: 'CASCADE',
})
notice!: Notice;
notice!: Relation<Notice>;

@ManyToOne(() => Tag, (tag) => tag.noticeTags, {
nullable: false,
onDelete: 'CASCADE',
})
tag!: Tag;
tag!: Relation<Tag>;

@RelationId((noticeTag: NoticeTag) => noticeTag.notice)
noticeId!: number;
Expand Down
2 changes: 1 addition & 1 deletion src/department/department.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@nestjs/common';
import { In, ObjectLiteral } from 'typeorm';

import { Department, Tag, UserTag } from './department.entity';
import { Department, Tag, UserTag } from './department.entity.js';
import { PreFollow, UserRequest } from '../types/custom-type';
import { FollowDto } from './dto/follow.dto';
import { User } from '../user/user.entity';
Expand Down
2 changes: 1 addition & 1 deletion src/fbconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import { config } from 'dotenv';
import { ServiceAccount } from 'firebase-admin/lib/credential';

import { getEnvFile } from './functions/custom-function';
import { getEnvFile } from './functions/custom-function.js';

const envFile = getEnvFile();
config({ path: path.resolve(process.cwd(), envFile) });
Expand Down
2 changes: 1 addition & 1 deletion src/firebase/firebase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as admin from 'firebase-admin';

import { fbConfig } from '../fbconfig';
import { encodeTag } from '../functions/custom-function';
import { User } from '../user/user.entity';
import { User } from '../user/user.entity.js';

@Injectable()
export class FirebaseService {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/custom-function.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BadRequestException, HttpStatus } from '@nestjs/common';
import { ValidationError } from 'class-validator';

import { Department } from '../department/department.entity';
import { Department } from '../department/department.entity.js';
import { StringKey } from '../types/custom-type';

export function exceptionFormatter(validationErrors: ValidationError[] = []): BadRequestException {
Expand Down
3 changes: 1 addition & 2 deletions src/notice/dto/noticesResponse.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IsString } from 'class-validator';

import { Notice } from '../notice.entity';
import { Notice } from '../notice.entity.js';

export class NoticesResponseDto {
notices!: Notice[];
Expand Down
3 changes: 2 additions & 1 deletion src/notice/notice.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import { Notice } from './notice.entity';
import { NoticeService } from './notice.service';
import { JwtAccessGuard } from '../auth/auth.guard';
import { UserRequest } from '../types/custom-type';
import { GetNoticeInDeptDto } from './dto/getNoticeInDept.dto';

import { NoticePaginationDto } from './dto/noticePagination.dto';
import { NoticesResponseDto } from './dto/noticesResponse.dto';
import { SearchFollowedNoticeDto } from './dto/searchFollowedNotice.dto';
import { SearchNoticeInDeptDto } from './dto/searchNoticeInDept.dto';
import { GetNoticeInDeptDto } from './dto/getNoticeInDept.dto';

@UseGuards(JwtAccessGuard)
@Controller('notices')
Expand Down
22 changes: 11 additions & 11 deletions src/notice/notice.entity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Exclude, Expose } from 'class-transformer';
import { BaseEntity, Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { BaseEntity, Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn, Relation } from 'typeorm';

import { PREVIEW_LENGTH } from './constants';
import { Department, NoticeTag } from '../department/department.entity';
import { User } from '../user/user.entity';
import { PREVIEW_LENGTH } from './constants.js';
import { Department, NoticeTag } from '../department/department.entity.js';
import { User } from '../user/user.entity.js';

@Entity()
@Index(['createdAt', 'id'])
Expand Down Expand Up @@ -42,7 +42,7 @@ export class Notice extends BaseEntity {
nullable: false,
onDelete: 'CASCADE',
})
department!: Department;
department!: Relation<Department>;

@Exclude()
@Column()
Expand All @@ -65,14 +65,14 @@ export class Notice extends BaseEntity {

@Exclude()
@OneToMany(() => UserNotice, (userNotice) => userNotice.notice)
userNotices!: UserNotice[];
userNotices!: Relation<UserNotice[]>;

@OneToMany(() => File, (file) => file.notice)
files!: File[];
files!: Relation<File[]>;

@Exclude()
@OneToMany(() => NoticeTag, (noticeTag) => noticeTag.notice)
noticeTags!: NoticeTag[];
noticeTags!: Relation<NoticeTag[]>;

@Expose()
get tags(): string[] {
Expand Down Expand Up @@ -105,7 +105,7 @@ export class File extends BaseEntity {
nullable: false,
onDelete: 'CASCADE',
})
notice!: Notice;
notice!: Relation<Notice>;
}

@Entity()
Expand All @@ -120,11 +120,11 @@ export class UserNotice extends BaseEntity {
nullable: false,
onDelete: 'CASCADE',
})
user!: User;
user!: Relation<User>;

@ManyToOne(() => Notice, (notice) => notice.userNotices, {
nullable: false,
onDelete: 'CASCADE',
})
notice!: Notice;
notice!: Relation<Notice>;
}
11 changes: 5 additions & 6 deletions src/notice/notice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import {
NotFoundException,
UnauthorizedException,
} from '@nestjs/common';
import { validate } from 'class-validator';
import { Brackets, In, ObjectLiteral, SelectQueryBuilder } from 'typeorm';

import { Notice, UserNotice } from './notice.entity';
import { User } from '../user/user.entity';
import { User } from '../user/user.entity.js';
import { Notice, UserNotice } from './notice.entity.js';
import { GetNoticeInDeptDto } from './dto/getNoticeInDept.dto';
import { NoticesResponseDto } from './dto/noticesResponse.dto';
import { Department, NoticeTag, Tag, UserTag } from '../department/department.entity';
import { Department, NoticeTag, Tag, UserTag } from '../department/department.entity.js';
import { Brackets, In, ObjectLiteral, SelectQueryBuilder } from 'typeorm';
import { orderType, PreNotice, PreQuery, UserDepartment, UserRequest } from '../types/custom-type';
import { NoticePaginationDto } from './dto/noticePagination.dto';
import { SearchFollowedNoticeDto } from './dto/searchFollowedNotice.dto';
import { SearchNoticeInDeptDto } from './dto/searchNoticeInDept.dto';
import { exceptionFormatter } from '../functions/custom-function';
import { validate } from 'class-validator';

const emptyResponse: NoticesResponseDto = { notices: [], next_cursor: '' };
@Injectable()
Expand Down
6 changes: 3 additions & 3 deletions src/types/custom-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import exp from 'constants';

import { Request } from 'express';

import { Department, Tag, UserTag } from '../department/department.entity';
import { Department, Tag, UserTag } from '../department/department.entity.js';
import { NoticePaginationDto } from '../notice/dto/noticePagination.dto';
import { Notice, UserNotice } from '../notice/notice.entity';
import { User } from '../user/user.entity';
import { Notice, UserNotice } from '../notice/notice.entity.js';
import { User } from '../user/user.entity.js';

export class Payload {
username!: string;
Expand Down
7 changes: 3 additions & 4 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Body, Controller, Delete, Get, HttpCode, Post, Req, UseGuards } from '@nestjs/common';

import { AuthDto } from './dto/auth-user.dto';
import { CreateUserDto } from './dto/create-user.dto';
import { User } from './user.entity';
import { UserService } from './user.service';
import { User } from './user.entity.js';
import { CreateUserDto } from './dto/create-user.dto';
import { AuthTokenGuard, JwtAccessGuard } from '../auth/auth.guard';
import { UserRequest } from '../types/custom-type';
import { FcmTopicDto } from './dto/fcm-topic.dto';
import { AuthDto } from './dto/auth-user.dto';

@Controller('users')
export class UserController {
Expand Down
4 changes: 2 additions & 2 deletions src/user/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as bcrypt from 'bcrypt';
import { Exclude } from 'class-transformer';
import { BaseEntity, Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';

import { UserTag } from '../department/department.entity';
import { UserNotice } from '../notice/notice.entity';
import { UserTag } from '../department/department.entity.js';
import { UserNotice } from '../notice/notice.entity.js';

@Entity()
export class User extends BaseEntity {
Expand Down
2 changes: 1 addition & 1 deletion src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';

import { CreateUserDto } from './dto/create-user.dto';
import { User } from './user.entity';
import { User } from './user.entity.js';
import { AuthService } from '../auth/auth.service';
import { UserRequest } from '../types/custom-type';
import { FcmTopicDto } from './dto/fcm-topic.dto';
Expand Down
3 changes: 1 addition & 2 deletions src/user/user.validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator';

import { User } from './user.entity';
import { User } from './user.entity.js';

@ValidatorConstraint({ async: true })
export class UniqueUsernameValidator implements ValidatorConstraintInterface {
Expand Down
6 changes: 3 additions & 3 deletions utils/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createConnection, Connection, getConnection } from 'typeorm';
import { Notice } from '../src/notice/notice.entity';
import { Department } from '../src/department/department.entity';
import * as ormConfig from '../src/ormconfig';
import { Notice } from '../src/notice/notice.entity.js';
import { Department } from '../src/department/department.entity.js';
import * as ormConfig from '../src/ormconfig.js';

async function search(keyword: string, departments: number[], searchType: string) {
let noticeNum = 0;
Expand Down

0 comments on commit 19a9895

Please sign in to comment.