import { Console } from "hsconsole"; import Badge from "../entities/Badge"; import BadgeRepo from "../repos/BadgeRepo"; export default abstract class BadgeService { public static async SaveBadge(currentUserId:number, id:number | undefined, name:string, description:string, imageUrl: string, forUrl:string) { try { let badge = id ? await BadgeRepo.selectById(id) : null; if (badge === null) { badge = new Badge(); badge.CreatedByUserId = currentUserId; badge.CreatedDatetime = new Date(); } else { badge.LastModifiedByUserId = currentUserId; badge.LastModifiedDatetime = new Date(); } badge.Name = name; badge.Description = description; badge.ImageUrl = imageUrl; badge.ForUrl = forUrl; return await BadgeRepo.insertUpdate(badge); } catch (e) { Console.printError(`MultiProbe server service error:\n${e}`); throw e; } } public static async LoadBadge(id:number) { try { return await BadgeRepo.selectById(id); } catch (e) { Console.printError(`MultiProbe server service error:\n${e}`); throw e; } } public static async LoadAll() { try { return await BadgeRepo.selectAll(); } catch (e) { Console.printError(`MultiProbe server service error:\n${e}`); throw e; } } public static async DeleteBadge(currentUserId:number, id: number) { const badge = await BadgeRepo.selectById(id); if (badge == null) { return null; } badge.DeletedByUserId = currentUserId; badge.DeletedDatetime = new Date(); badge.IsDeleted = true; return await BadgeRepo.insertUpdate(badge); } }