Compare commits
5 Commits
684e7c4ddb
...
d2c826c7c9
Author | SHA1 | Date | |
---|---|---|---|
d2c826c7c9 | |||
34d4ebc7cb | |||
8d1dd78194 | |||
9395813f5a | |||
33d159dbcf |
53
src/models/CreateUser.ts
Normal file
53
src/models/CreateUser.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { IsInt, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||||
|
import { User } from '../models/User';
|
||||||
|
import { getConnectionManager } from 'typeorm';
|
||||||
|
import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../errors/CreateUserErrors';
|
||||||
|
import { UserGroup } from './UserGroup';
|
||||||
|
|
||||||
|
export class CreateUser {
|
||||||
|
@IsString()
|
||||||
|
firstname: string;
|
||||||
|
@IsString()
|
||||||
|
middlename?: string;
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
username?: string;
|
||||||
|
@IsPhoneNumber("ZZ")
|
||||||
|
@IsOptional()
|
||||||
|
phone?: string;
|
||||||
|
@IsString()
|
||||||
|
password: string;
|
||||||
|
@IsString()
|
||||||
|
lastname: string;
|
||||||
|
@IsString()
|
||||||
|
email?: string;
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
groupId?: number[] | number
|
||||||
|
|
||||||
|
public async toUser(): Promise<User> {
|
||||||
|
let newUser: User = new User();
|
||||||
|
|
||||||
|
if (this.email === undefined && this.username === undefined) {
|
||||||
|
throw new UsernameOrEmailNeededError();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.groupId) {
|
||||||
|
// TODO: link user groups
|
||||||
|
// newUser.groups = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: this.teamId });
|
||||||
|
} else {
|
||||||
|
throw new UserGroupNotFoundError();
|
||||||
|
}
|
||||||
|
|
||||||
|
newUser.email = this.email
|
||||||
|
newUser.username = this.username
|
||||||
|
newUser.firstname = this.firstname
|
||||||
|
newUser.middlename = this.middlename
|
||||||
|
newUser.lastname = this.lastname
|
||||||
|
// TODO: hash password here or in controller/ in User model via setter?
|
||||||
|
newUser.password = this.password
|
||||||
|
|
||||||
|
console.log(newUser)
|
||||||
|
return newUser;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
|
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
|
||||||
import {
|
import {
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
|
IsEAN,
|
||||||
IsInt,
|
IsInt,
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
@ -32,12 +33,12 @@ export class RunnerCard {
|
|||||||
/**
|
/**
|
||||||
* The card's code.
|
* The card's code.
|
||||||
* This has to be able to being converted to something barcode compatible.
|
* This has to be able to being converted to something barcode compatible.
|
||||||
* Probably gonna be autogenerated.
|
* could theoretically be autogenerated
|
||||||
*/
|
*/
|
||||||
@Column()
|
@Column()
|
||||||
|
@IsEAN()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
//TODO: Generate this
|
|
||||||
code: string;
|
code: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,11 +35,19 @@ export abstract class Scan {
|
|||||||
@IsPositive()
|
@IsPositive()
|
||||||
abstract distance: number;
|
abstract distance: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the scan valid (for fraud reasons).
|
* Is the scan valid (for fraud reasons).
|
||||||
* Default: true
|
* Default: true
|
||||||
*/
|
*/
|
||||||
@Column()
|
@Column()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
valid: boolean = true;
|
valid: boolean = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* seconds since last scan
|
||||||
|
*/
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
secondsSinceLastScan: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique, JoinTable, ManyToMany } from "typeorm";
|
import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique, JoinTable, ManyToMany } from "typeorm";
|
||||||
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator";
|
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, isUUID, } from "class-validator";
|
||||||
import { UserGroup } from './UserGroup';
|
import { UserGroup } from './UserGroup';
|
||||||
import { Permission } from './Permission';
|
import { Permission } from './Permission';
|
||||||
import { UserAction } from './UserAction';
|
import { UserAction } from './UserAction';
|
||||||
@ -31,6 +31,13 @@ export class User {
|
|||||||
@IsEmail()
|
@IsEmail()
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user phone
|
||||||
|
*/
|
||||||
|
@IsPhoneNumber("ZZ")
|
||||||
|
@IsOptional()
|
||||||
|
phone: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* username
|
* username
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user