t00-multiuser/server/services/UserService.ts

46 lines
1.3 KiB
TypeScript

import { Console } from "hsconsole";
import User from "../objects/User";
import PartyRepo from "../repos/PartyRepo";
import UserRepo from "../repos/UserRepo";
import PasswordUtility from "../utilities/PasswordUtility";
export default class UserService {
public static async GetUser(id:number) {
try {
return await UserRepo.selectById(id);
} catch (e) {
Console.printError(`MultiProbe server service error:\n${e}`);
}
}
public static async GetParty(id:number) {
try {
return await PartyRepo.selectById(id);
} catch (e) {
Console.printError(`MultiProbe server service error:\n${e}`);
}
}
public static async GetPartyByPartyRef(partyRef:string) {
try {
return await PartyRepo.selectByPartyRef(partyRef);
} catch (e) {
Console.printError(`MultiProbe server service error:\n${e}`);
}
}
public static async CreateUser(currentUserId:number, username:string, password:string) {
try {
const user = new User();
user.Username = username;
user.PasswordSalt = PasswordUtility.GenerateSalt();
user.PasswordHash = await PasswordUtility.HashPassword(user.PasswordSalt, password);
user.CreatedByUserId = currentUserId;
user.CreatedDatetime = new Date();
await UserRepo.insertUpdate(user);
} catch (e) {
Console.printError(`MultiProbe server service error:\n${e}`);
}
}
}