Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MARXAN-1643-modify-signup-to-include-bakground #1142

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddBackgroundColumnsToUser1655459736009
implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE background_options AS ENUM (
'academic_research',
'conservation_planning'
);

CREATE TYPE level_options AS ENUM (
'trainee',
'student',
'phd',
'faculty',
'ngo',
'private_sector',
'government',
'intergovernmental'
);

ALTER TABLE users
ADD COLUMN background background_options,
ADD COLUMN level level_options;
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE users
DROP COLUMN background,
DROP COLUMN level;

DROP TYPE level_options;
DROP TYPE background_options;
`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export class AuthenticationService {
user.email = signupDto.email;
user.fname = signupDto.fname;
user.lname = signupDto.lname;
user.background = signupDto.background;
user.level = signupDto.level;
const newUser = UsersService.getSanitizedUserMetadata(
await this.usersRepository.save(user),
);
Expand Down
27 changes: 27 additions & 0 deletions api/apps/api/src/modules/authentication/dto/sign-up.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
IsDefined,
IsEmail,
IsEnum,
IsNotEmpty,
IsOptional,
IsString,
} from 'class-validator';

export enum Backgrounds {
academic_research_science = 'academic_research',
conservation_planning = 'conservation_planning',
}

export enum Levels {
trainee = 'trainee',
student = 'student',
phd = 'phd',
faculty = 'faculty',
ngo = 'ngo',
private_sector = 'private_sector',
government = 'government',
intergovernmental = 'intergovernmental',
}

export class SignUpDto {
@IsOptional()
@IsString()
Expand Down Expand Up @@ -35,4 +52,14 @@ export class SignUpDto {
@IsString()
@ApiPropertyOptional()
lname?: string;

@IsOptional()
@IsEnum(Backgrounds)
@ApiPropertyOptional()
background?: Backgrounds;

@IsOptional()
@IsEnum(Levels)
@ApiPropertyOptional()
level?: Levels;
}
12 changes: 12 additions & 0 deletions api/apps/api/src/modules/users/user.api.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import { Project } from '../projects/project.api.entity';
import { Scenario } from '../scenarios/scenario.api.entity';
import { BaseServiceResource } from '../../types/resource.interface';
import { IsEnum } from 'class-validator';
import { Backgrounds, Levels } from '../authentication/dto/sign-up.dto';

export const userResource: BaseServiceResource = {
className: 'User',
Expand Down Expand Up @@ -43,6 +45,16 @@ export class User {
@Column('character varying')
lname?: string | null;

@ApiPropertyOptional()
@Column('character varying')
@IsEnum(Backgrounds)
background?: Backgrounds;

@ApiPropertyOptional()
@Column('character varying')
@IsEnum(Levels)
level?: Levels;

/**
* User avatar, stored as data url.
*
Expand Down