Compare commits

..

No commits in common. "a1105f06abf28d72b691c9431fd54083a82d8318" and "74ee77f814c269718cb99847e4a43600fc52b41f" have entirely different histories.

21 changed files with 117 additions and 133 deletions

View File

@ -7,71 +7,26 @@ import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup';
export class CreateUser {
/**
* The new user's first name.
*/
@IsString()
firstname: string;
/**
* The new user's middle name.
* Optinal.
*/
@IsString()
@IsOptional()
middlename?: string;
/**
* The new user's last name.
*/
@IsString()
lastname: string;
/**
* The new user's username.
* You have to provide at least one of: {email, username}.
*/
@IsOptional()
@IsString()
username?: string;
/**
* The new user's email address.
* You have to provide at least one of: {email, username}.
*/
@IsEmail()
@IsString()
@IsOptional()
email?: string;
/**
* The new user's phone number.
* Optional
*/
@IsPhoneNumber("ZZ")
@IsOptional()
phone?: string;
/**
* The new user's password.
* This will of course not be saved in plaintext :)
*/
@IsString()
password: string;
/**
* The new user's groups' id(s).
* You can provide either one groupId or an array of groupIDs.
* Optional.
*/
@IsString()
lastname: string;
@IsEmail()
@IsString()
email?: string;
@IsOptional()
groupId?: number[] | number
//TODO: ProfilePics
/**
* Converts this to a User Entity.
*/
public async toUser(): Promise<User> {
let newUser: User = new User();
@ -103,16 +58,17 @@ export class CreateUser {
}
}
const new_uuid = uuid.v4()
newUser.email = this.email
newUser.username = this.username
newUser.firstname = this.firstname
newUser.middlename = this.middlename
newUser.lastname = this.lastname
newUser.uuid = uuid.v4()
newUser.phone = this.phone
newUser.password = await argon2.hash(this.password + newUser.uuid);
//TODO: ProfilePics
newUser.uuid = new_uuid
newUser.password = await argon2.hash(this.password + new_uuid);
console.log(newUser)
return newUser;
}
}

View File

@ -1,30 +1,28 @@
import { IsOptional, IsString } from 'class-validator';
import { GroupNameNeededError } from '../../errors/UserGroupErrors';
import { UserGroup } from '../entities/UserGroup';
export class CreateUserGroup {
/**
* The new group's name.
*/
@IsOptional()
@IsString()
name: string;
/**
* The new group's description.
* Optinal.
*/
@IsOptional()
@IsString()
description?: string;
/**
* Converts this to a UserGroup entity.
*/
public async toUserGroup(): Promise<UserGroup> {
let newUserGroup: UserGroup = new UserGroup();
newUserGroup.name = this.name;
newUserGroup.description = this.description;
if (this.name === undefined) {
throw new GroupNameNeededError();
}
newUserGroup.name = this.name
if (this.description) {
newUserGroup.description = this.description
}
console.log(newUserGroup)
return newUserGroup;
}
}

View File

@ -1,11 +1,11 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsPostalCode,
IsString
IsString,
} from "class-validator";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Participant } from "./Participant";
import { RunnerOrganisation } from "./RunnerOrganisation";
@ -18,13 +18,14 @@ export class Address {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The address's description.
*/
@Column({ nullable: true })
@Column({nullable: true})
@IsString()
@IsOptional()
description?: string;
@ -42,7 +43,7 @@ export class Address {
* The address's second line.
* Containing optional information.
*/
@Column({ nullable: true })
@Column({nullable: true})
@IsString()
@IsOptional()
address2?: string;

View File

@ -13,7 +13,7 @@ export class DistanceDonation extends Donation {
* The runner associated.
*/
@IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.distanceDonations)
@ManyToOne(() => Runner, runner => runner.distanceDonations, { nullable: true })
runner: Runner;
/**

View File

@ -1,6 +1,7 @@
import {
IsInt,
IsNotEmpty
IsNotEmpty,
IsOptional
} from "class-validator";
import { Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Participant } from "./Participant";
@ -15,6 +16,7 @@ export abstract class Donation {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
@ -22,7 +24,7 @@ export abstract class Donation {
* The donations's donor.
*/
@IsNotEmpty()
@ManyToOne(() => Participant, donor => donor.donations)
@ManyToOne(() => Participant, donor => donor.donations, { nullable: true })
donor: Participant;
/**

View File

@ -1,5 +1,5 @@
import { Entity, Column, ChildEntity } from "typeorm";
import { IsBoolean } from "class-validator";
import { ChildEntity, Column } from "typeorm";
import { Participant } from "./Participant";
/**

View File

@ -1,5 +1,5 @@
import { IsInt, IsPositive } from "class-validator";
import { ChildEntity, Column } from "typeorm";
import { Entity, Column, ChildEntity } from "typeorm";
import { IsInt, IsPositive, } from "class-validator";
import { Donation } from "./Donation";
/**

View File

@ -1,14 +1,15 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
import {
IsEmail,
IsInt,
IsNotEmpty,
IsOptional,
IsPhoneNumber,
IsString
IsPositive,
IsString,
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Address } from "./Address";
import { Donation } from "./Donation";
import { RunnerGroup } from "./RunnerGroup";
/**
@ -16,10 +17,11 @@ import { RunnerGroup } from "./RunnerGroup";
*/
@Entity()
export class GroupContact {
/**
* Autogenerated unique id (primary key).
*/
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
@ -35,7 +37,7 @@ export class GroupContact {
* The contact's middle name.
* Optional
*/
@Column({ nullable: true })
@Column({nullable: true})
@IsOptional()
@IsString()
middlename?: string;
@ -60,7 +62,7 @@ export class GroupContact {
* The contact's phone number.
* Optional
*/
@Column({ nullable: true })
@Column({nullable: true})
@IsOptional()
@IsPhoneNumber("DE")
phone?: string;
@ -69,13 +71,19 @@ export class GroupContact {
* The contact's email address.
* Optional
*/
@Column({ nullable: true })
@Column({nullable: true})
@IsOptional()
@IsEmail()
email?: string;
/**
* Used to link contacts to groups.
* Used to link the contact as the donor of a donation.
*/
@OneToMany(() => Donation, donation => donation.donor, { nullable: true })
donations: Donation[];
/**
* Used to link runners to donations.
*/
@OneToMany(() => RunnerGroup, group => group.contact, { nullable: true })
groups: RunnerGroup[];

View File

@ -1,13 +1,13 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity, TableInheritance } from "typeorm";
import {
IsEmail,
IsInt,
IsNotEmpty,
IsOptional,
IsPhoneNumber,
IsString
IsPositive,
IsString,
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Address } from "./Address";
import { Donation } from "./Donation";
@ -21,6 +21,7 @@ export abstract class Participant {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;

View File

@ -1,10 +1,10 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsString
IsOptional,
IsString,
} from "class-validator";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { User } from './User';
import { UserGroup } from './UserGroup';
/**
@ -16,6 +16,7 @@ export abstract class Permission {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;

View File

@ -15,7 +15,7 @@ export class Runner extends Participant {
* The runner's associated group.
*/
@IsNotEmpty()
@ManyToOne(() => RunnerGroup, group => group.runners, { nullable: false })
@ManyToOne(() => RunnerGroup, group => group.runners, { nullable: true })
group: RunnerGroup;
/**

View File

@ -1,12 +1,12 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
import {
IsBoolean,
IsEAN,
IsInt,
IsNotEmpty,
IsOptional,
IsString
IsString,
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Runner } from "./Runner";
import { TrackScan } from "./TrackScan";
@ -19,6 +19,7 @@ export class RunnerCard {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;

View File

@ -18,11 +18,12 @@ export abstract class RunnerGroup {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The group's name.
* The group's first name.
*/
@Column()
@IsNotEmpty()

View File

@ -15,7 +15,7 @@ export class RunnerTeam extends RunnerGroup {
* Optional
*/
@IsNotEmpty()
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: false })
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
parentGroup?: RunnerOrganisation;
/**

View File

@ -1,11 +1,11 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, TableInheritance } from "typeorm";
import {
IsBoolean,
IsInt,
IsNotEmpty,
IsPositive
IsOptional,
IsPositive,
} from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Runner } from "./Runner";
/**
@ -18,6 +18,7 @@ export abstract class Scan {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
@ -25,7 +26,7 @@ export abstract class Scan {
* The associated runner.
*/
@IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.scans, { nullable: false })
@ManyToOne(() => Runner, runner => runner.scans, { nullable: true })
runner: Runner;
/**
@ -42,4 +43,12 @@ export abstract class Scan {
@Column()
@IsBoolean()
valid: boolean = true;
}
/**
* seconds since last scan
*/
@IsInt()
@IsOptional()
secondsSinceLastScan: number;
}

View File

@ -1,11 +1,11 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
import {
IsBoolean,
IsInt,
IsNotEmpty,
IsOptional,
IsString
IsString,
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Track } from "./Track";
import { TrackScan } from "./TrackScan";
@ -18,13 +18,14 @@ export class ScanStation {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The station's description.
*/
@Column({ nullable: true })
@Column({nullable: true})
@IsOptional()
@IsString()
description?: string;
@ -33,7 +34,7 @@ export class ScanStation {
* The track this station is associated with.
*/
@IsNotEmpty()
@ManyToOne(() => Track, track => track.stations, { nullable: false })
@ManyToOne(() => Track, track => track.stations, { nullable: true })
track: Track;
/**

View File

@ -1,11 +1,11 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
IsString
IsString,
} from "class-validator";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { ScanStation } from "./ScanStation";
import { TrackScan } from "./TrackScan";
@ -18,6 +18,7 @@ export class Track {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;;

View File

@ -1,15 +1,17 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, ChildEntity } from "typeorm";
import {
IsBoolean,
IsDateString,
IsInt,
IsNotEmpty,
IsPositive
IsOptional,
IsPositive,
} from "class-validator";
import { ChildEntity, Column, ManyToOne } from "typeorm";
import { RunnerCard } from "./RunnerCard";
import { Scan } from "./Scan";
import { ScanStation } from "./ScanStation";
import { Runner } from "./Runner";
import { Track } from "./Track";
import { RunnerCard } from "./RunnerCard";
import { ScanStation } from "./ScanStation";
/**
* Defines the scan interface.

View File

@ -13,6 +13,7 @@ export class User {
* autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
@ -20,30 +21,30 @@ export class User {
* uuid
*/
@Column()
@IsUUID(4)
@IsUUID("4")
uuid: string;
/**
* user email
*/
@Column({ nullable: true })
@Column()
@IsEmail()
email?: string;
email: string;
/**
* user phone
*/
@Column({ nullable: true })
@IsOptional()
@Column()
@IsPhoneNumber("ZZ")
phone?: string;
@IsOptional()
phone: string;
/**
* username
*/
@Column({ nullable: true })
@Column()
@IsString()
username?: string;
username: string;
/**
* firstname
@ -56,10 +57,10 @@ export class User {
/**
* middlename
*/
@Column({ nullable: true })
@Column()
@IsString()
@IsOptional()
middlename?: string;
middlename: string;
/**
* lastname
@ -82,7 +83,7 @@ export class User {
*/
@IsOptional()
@ManyToOne(() => Permission, permission => permission.users, { nullable: true })
permissions?: Permission[];
permissions: Permission[];
/**
* groups
@ -104,22 +105,21 @@ export class User {
*/
@IsInt()
@Column({ default: 1 })
refreshTokenCount?: number;
refreshTokenCount: number;
/**
* profilepic
*/
@Column({ nullable: true })
@Column()
@IsString()
@IsOptional()
profilePic?: string;
profilePic: string;
/**
* actions
*/
@IsOptional()
@OneToMany(() => UserAction, action => action.user, { nullable: true })
actions: UserAction[]
actions: UserAction
/**
* calculate all permissions

View File

@ -1,10 +1,10 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsString
IsString,
} from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { User } from './User';
/**
@ -16,6 +16,7 @@ export class UserAction {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;

View File

@ -16,6 +16,7 @@ export class UserGroup {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;