Skip to content

Commit

Permalink
Merge pull request #60 from richard483/fix-1
Browse files Browse the repository at this point in the history
updated upload company profile api & removed rating interface
  • Loading branch information
richard483 authored Jan 20, 2024
2 parents 89a5660 + f62ac52 commit 1ab08e0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend-8tech",
"version": "4.1.1",
"version": "4.1.2",
"description": "",
"author": "8tech",
"private": true,
Expand Down
5 changes: 0 additions & 5 deletions src/rating/interface/rating.interface.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/rating/test/rating.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { JwtAuthGuard } from '../../auth/jwt/jwt-auth.guard';
import { RoleGuard } from '../../auth/roles/role.guard';
import { RatingController } from '../rating.controller';
import { RatingService } from '../rating.service';
import { IRating } from '../interface/rating.interface';
import { RatingCreateDto } from '../dto/rating-create.dto';
import { RatingUpdateDto } from '../dto/rating-update.dto';
import { Rating } from '@prisma/client';
Expand Down
7 changes: 5 additions & 2 deletions src/rating/test/rating.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { RatingService } from '../rating.service';
import { IRating } from '../interface/rating.interface';
import { RatingRepository } from '../rating.repository';
import { RatingCreateDto } from '../dto/rating-create.dto';
import { RatingUpdateDto } from '../dto/rating-update.dto';
import { Rating } from '@prisma/client';

describe('RatingService', () => {
let service: RatingService;
let reposiotry: DeepMocked<RatingRepository>;
let ratingMock: IRating;
let ratingMock: Rating;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -24,6 +24,9 @@ describe('RatingService', () => {
id: 'randomId',
recruiterUserId: 'randomUserId',
ratingOf10: 9,
createdAt: new Date(),
updatedAt: new Date(),
userId: 'randomUserId',
};
});

Expand Down
1 change: 1 addition & 0 deletions src/users/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class UserController {
const response = await this.userService.uploadProfilePicture(
file,
req.user.companyId,
true,
);
return response;
}
Expand Down
9 changes: 8 additions & 1 deletion src/users/users.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import { PrismaService } from '../prisma/prisma.service';
import { UserController } from './user.controller';
import { UserRepository } from './user.repository';
import { UserHelper } from './user.helper';
import { CompanyRepository } from '../company/company.repository';

@Module({
providers: [UsersService, PrismaService, UserRepository, UserHelper],
providers: [
UsersService,
PrismaService,
UserRepository,
UserHelper,
CompanyRepository,
],
exports: [UsersService],
controllers: [UserController],
})
Expand Down
13 changes: 11 additions & 2 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { UserRepository } from './user.repository';
import { UserFilterRequestDto } from './dto/user-filter.dto';
import { UserHelper } from './user.helper';
import { User } from '@prisma/client';
import { CompanyRepository } from '../company/company.repository';

@Injectable()
export class UsersService {
constructor(
private userRepository: UserRepository,
private companyRepository: CompanyRepository,
private userHelper: UserHelper,
) {}

Expand Down Expand Up @@ -76,6 +78,7 @@ export class UsersService {
async uploadProfilePicture(
image: Express.Multer.File,
userId: string,
isCompany?: boolean,
): Promise<any | null> {
try {
const imageData = await this.userHelper.uploadImageToStorage(
Expand All @@ -84,10 +87,16 @@ export class UsersService {
? userId + `.${image.originalname.split('.').pop()}`
: image.originalname,
);
const { password, ...user } = await this.userRepository.update(userId, {
if (!isCompany) {
const { password, ...user } = await this.userRepository.update(userId, {
profilePicture: imageData.url,
});
return user;
}
const res = await this.companyRepository.update(userId, {
profilePicture: imageData.url,
});
return user;
return res;
} catch (error) {
console.log('#uploadProfilePicture error', error);
throw new HttpException(error, HttpStatus.BAD_REQUEST);
Expand Down

0 comments on commit 1ab08e0

Please sign in to comment.