diff --git a/apps/backend/src/users/types.ts b/apps/backend/src/users/types.ts new file mode 100644 index 0000000..526edb0 --- /dev/null +++ b/apps/backend/src/users/types.ts @@ -0,0 +1,7 @@ +export enum Status { + MEMBER = 'MEMBER', + RECRUITER = 'RECRUITER', + ADMIN = 'ADMIN', + ALUMNI = 'ALUMNI', + APPLICANT = 'APPLICANT', +} diff --git a/apps/backend/src/users/user.entity.ts b/apps/backend/src/users/user.entity.ts index fb43b7f..4353cc4 100644 --- a/apps/backend/src/users/user.entity.ts +++ b/apps/backend/src/users/user.entity.ts @@ -1,9 +1,12 @@ -import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; - +import { Entity, Column, ObjectIdColumn, ObjectId } from 'typeorm'; +import { Status } from './types'; @Entity() export class User { - @PrimaryGeneratedColumn() - id: number; + @ObjectIdColumn() // https://github.com/typeorm/typeorm/issues/1584 + userId: ObjectId; + + @Column() + status: Status; @Column() firstName: string; @@ -13,4 +16,19 @@ export class User { @Column() email: string; + + @Column() + profilePicture: string; + + @Column() + linkedin: string | null; + + @Column() + github: string | null; + + @Column() + team: string | null; + + @Column() + role: string | null; } diff --git a/apps/backend/src/users/users.controller.ts b/apps/backend/src/users/users.controller.ts index 55f0c84..3b11315 100644 --- a/apps/backend/src/users/users.controller.ts +++ b/apps/backend/src/users/users.controller.ts @@ -1,4 +1,10 @@ -import { Controller, Get } from '@nestjs/common'; +import { + DefaultValuePipe, + ParseBoolPipe, + Query, + Controller, + Get, +} from '@nestjs/common'; import { UsersService } from './users.service'; @@ -7,7 +13,10 @@ export class UsersController { constructor(private readonly usersService: UsersService) {} @Get() - getAllUsers() { - return this.usersService.findAll(); + getAllMembers( + @Query('getAllMembers', new DefaultValuePipe(false), ParseBoolPipe) + getAllMembers: boolean, + ) { + return this.usersService.findAll(getAllMembers); } } diff --git a/apps/backend/src/users/users.service.ts b/apps/backend/src/users/users.service.ts index 7c477d9..00a0e58 100644 --- a/apps/backend/src/users/users.service.ts +++ b/apps/backend/src/users/users.service.ts @@ -1,17 +1,44 @@ -import { Injectable } from '@nestjs/common'; +import { UnauthorizedException, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; +import { MongoRepository } from 'typeorm'; import { User } from './user.entity'; +import { Status } from './types'; +import { ObjectId } from 'mongodb'; @Injectable() export class UsersService { constructor( @InjectRepository(User) - private usersRepository: Repository, + private usersRepository: MongoRepository, ) {} - findAll(): Promise { - return this.usersRepository.find(); + async findAll(getAllMembers: boolean): Promise { + if (!getAllMembers) return []; + + const exampleUser: User = { + userId: new ObjectId('a0f3efa0f3efa0f3efa0f3ef'), + status: Status.ADMIN, + firstName: 'jimmy', + lastName: 'jimmy2', + email: 'jimmy.jimmy2@mail.com', + profilePicture: null, + linkedin: null, + github: null, + team: null, + role: null, + }; + + if (exampleUser.status == Status.APPLICANT) { + throw new UnauthorizedException(); + } + + const users: User[] = await this.usersRepository.find({ + where: { + status: { $not: { $eq: Status.APPLICANT } }, + }, + }); + + return users; } } diff --git a/package.json b/package.json index cc41cf5..87e5a41 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "version": "0.0.0", "license": "MIT", "scripts": { - "format:check": "prettier --check apps/{frontend,backend}/src/**/*.{js,ts,tsx}", - "format": "prettier --write apps/{frontend,backend}/src/**/*.{js,ts,tsx}", + "format:check": "prettier --no-error-on-unmatched-pattern --check apps/{frontend,backend}/src/**/*.{js,ts,tsx}", + "format": "prettier --no-error-on-unmatched-pattern --write apps/{frontend,backend}/src/**/*.{js,ts,tsx}", "lint:check": "eslint apps/frontend --ext .ts,.tsx && eslint apps/backend --ext .ts,.tsx", "lint": "eslint apps/frontend --ext .ts,.tsx --fix && eslint apps/backend --ext .ts,.tsx --fix", "prepush": "yarn run format:check && yarn run lint:check",