Skip to content

Commit

Permalink
Merge pull request #228 from tnpfldyd/BE-fix/server-api
Browse files Browse the repository at this point in the history
ν”„λ‘œν•„ μ΅œμ‹ μ •λ³΄λ‘œ λ°›μ•„μ˜¬ 수 μžˆλ„λ‘ μˆ˜μ •
  • Loading branch information
Conut-1 authored Dec 8, 2023
2 parents 7eb7e5f + 4c1c642 commit b0df04f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
13 changes: 7 additions & 6 deletions nestjs-BE/server/src/base/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export abstract class BaseService<T extends HasUuid> {
message: 'Success',
data: mergedData,
};
} else {
throw new HttpException('Not Found', HttpStatus.NOT_FOUND);
}

throw new HttpException('Not Found', HttpStatus.NOT_FOUND);
}

async update(key: string, updateData: T) {
Expand All @@ -99,11 +99,12 @@ export abstract class BaseService<T extends HasUuid> {
message: 'Success',
data: updatedData.value,
};
} else {
return {
statusCode: HttpStatus.NOT_FOUND,
message: 'Not Found',
};
}
return {
statusCode: HttpStatus.NOT_FOUND,
message: 'Not Found',
};
}

async remove(key: string) {
Expand Down
14 changes: 10 additions & 4 deletions nestjs-BE/server/src/profile-space/profile-space.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { Injectable, HttpStatus } from '@nestjs/common';
import { UpdateProfileSpaceDto } from './dto/update-profile-space.dto';
import { BaseService } from 'src/base/base.service';
import { PrismaServiceMySQL } from 'src/prisma/prisma.service';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class ProfileSpaceService extends BaseService<UpdateProfileSpaceDto> {
async getUserSpaces(
userUuid: string,
profileUuid: string,
): Promise<UpdateProfileDto[]> {
): Promise<UpdateSpaceDto[]> {
const cacheUserSpaces = this.userCache.get(userUuid);
if (cacheUserSpaces) return cacheUserSpaces;
const profileResponse = await this.prisma['PROFILE_TB'].findUnique({
Expand All @@ -111,7 +111,7 @@ export class ProfileSpaceService extends BaseService<UpdateProfileSpaceDto> {
return storeUserSpaces;
}

async getSpaceUsers(spaceUuid: string): Promise<UpdateSpaceDto[]> {
async getSpaceUsers(spaceUuid: string): Promise<UpdateProfileDto[]> {
const cacheSpaceProfiles = this.spaceCache.get(spaceUuid);
if (cacheSpaceProfiles) return cacheSpaceProfiles;

Expand Down Expand Up @@ -145,10 +145,16 @@ export class ProfileSpaceService extends BaseService<UpdateProfileSpaceDto> {

async getUsers(spaceUuid: string) {
const users = await this.getSpaceUsers(spaceUuid);
const usersData = await Promise.all(
users.map(async (user) => {
return await this.profilesService.getDataFromCacheOrDB(user.user_id);
}),
);
this.spaceCache.put(spaceUuid, usersData);
return {
statusCode: HttpStatus.OK,
message: 'Success',
data: users,
data: usersData,
};
}
}
3 changes: 3 additions & 0 deletions nestjs-BE/server/src/spaces/dto/create-space.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';

export class CreateSpaceDto {
@IsString()
@IsNotEmpty()
@ApiProperty({ example: 'Sample Space', description: 'Name of the space' })
name: string;

Expand Down

0 comments on commit b0df04f

Please sign in to comment.