t00-multiuser/server/services/UserService.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-22 02:01:14 +01:00
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 GetUserByUsername(username:string) {
try {
return await UserRepo.selectByUsername(username);
} catch (e) {
Console.printError(`MultiProbe server service error:\n${e}`);
}
}
2024-04-22 02:01:14 +01:00
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}`);
}
}
}