Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Impeqq committed Nov 20, 2021
1 parent 0fb8f98 commit 36b4cbd
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 19,425 deletions.
1 change: 1 addition & 0 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
app.use(
graphqlUploadExpress({
maxFileSize: 100000000,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/user/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class UserEntity extends BaseEntity {
@Column('boolean', { default: false, nullable: true })
online: boolean;

@OneToOne(() => FileEntity)
@OneToOne(() => FileEntity, { nullable: true })
@JoinColumn()
avatar?: FileEntity;

Expand Down
2 changes: 1 addition & 1 deletion backend/src/user/user.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Socket, Server } from 'socket.io';
import { UserService } from './user.service';
import { pubsub } from 'src/lib/pubsub';

@WebSocketGateway(5001, { cors: true })
@WebSocketGateway({ cors: true })
export class UserGateway
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
@WebSocketServer() server: Server;
Expand Down
19 changes: 9 additions & 10 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { UserEntity } from './user.entity';
import { Repository } from 'typeorm';
import { ILike, Repository } from 'typeorm';
import * as jwt from 'jsonwebtoken';
import * as bcrypt from 'bcryptjs';
import { SignInInput, SignUpInput } from './dto/auth.inputs';
Expand Down Expand Up @@ -37,13 +37,12 @@ export class UserService {
async findByName(name: string, id: string) {
if (!name) return [];

return await this.userRepo
.createQueryBuilder('user')
.innerJoinAndSelect('user.avatar', 'file')
.where('user.firstName ILike :name', { name })
.orWhere('user.lastName ILike :name', { name })
.andWhere('user.id != :id', { id })
.getMany();
return await this.userRepo.find({
where: [
{ firstName: ILike(`%${name}%`) },
{ lastName: ILike(`%${name}%`) },
],
});
}

async findOne(id: string) {
Expand Down Expand Up @@ -81,8 +80,8 @@ export class UserService {
.where('id = :id', { id: user_id })
.execute();

if (avatar) {
await this.fileService.deleteDatabaseFile(oldUser.avatar.id);
if (avatar && oldUser.avatar?.id) {
await this.fileService.deleteDatabaseFile(oldUser.avatar?.id);
}

const user = await this.userRepo.findOne(user_id, {
Expand Down
Loading

0 comments on commit 36b4cbd

Please sign in to comment.