Skip to content
Snippets Groups Projects
Commit 787a1c02 authored by Samuli Virtapohja's avatar Samuli Virtapohja
Browse files

merge development to access

parents f7d55d7e 39308d36
No related branches found
No related tags found
2 merge requests!59Development to master,!18Join game
import { createParamDecorator } from "@nestjs/common"; import { createParamDecorator } from "@nestjs/common";
// used to pass user information to controllers
export const User = createParamDecorator((data, req) => { export const User = createParamDecorator((data, req) => {
return data ? req.user[data] : req.user; return data ? req.user[data] : req.user;
}) })
\ No newline at end of file
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany } from 'typeorm'; import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany } from 'typeorm';
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import * as jwt from 'jsonwebtoken'; import * as jwt from 'jsonwebtoken';
import { MapMarkerEntity } from '../mapmarkers/mapmarker.entity'; import { MapMarkerEntity } from '../mapmarkers/mapmarker.entity';
import { Game_PersonEntity } from '../game/game.entity';
@Entity('Person') @Entity('Person')
export class PersonEntity { export class PersonEntity {
...@@ -10,12 +12,17 @@ export class PersonEntity { ...@@ -10,12 +12,17 @@ export class PersonEntity {
@Column('text') password: string; @Column('text') password: string;
@OneToMany(type => MapMarkerEntity, marker => marker.player) @OneToMany(type => MapMarkerEntity, marker => marker.player)
markers: MapMarkerEntity[]; markers: MapMarkerEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.person)
game_persons: Game_PersonEntity[];
// hashes the password before inserting it to database
@BeforeInsert() @BeforeInsert()
async hashPassword() { async hashPassword() {
this.password = await bcrypt.hash(this.password, 10); this.password = await bcrypt.hash(this.password, 10);
} }
// returns username and associated token
tokenObject() { tokenObject() {
const {name, token} = this; const {name, token} = this;
return {name, token}; return {name, token};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment