private: Add until to token creation

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-01-21 12:33:45 +01:00 committed by David Mehren
parent 324ba71d24
commit 4784a1aea2
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 20 additions and 8 deletions

View file

@ -6,7 +6,6 @@
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { User } from './user.entity';
import { Type } from 'class-transformer';
@Entity()
export class AuthToken {
@ -25,16 +24,21 @@ export class AuthToken {
@Column({ unique: true })
accessToken: string;
@Column({ type: 'date' })
validUntil: Date;
public static create(
user: User,
identifier: string,
accessToken: string,
validUntil: Date,
): Pick<AuthToken, 'user' | 'accessToken'> {
const newToken = new AuthToken();
newToken.user = user;
newToken.identifier = identifier;
newToken.accessToken = accessToken;
newToken.createdAt = new Date();
newToken.validUntil = validUntil;
return newToken;
}
}