diff --git a/src/api/admin/AdminStickerService.ts b/src/api/admin/AdminStickerService.ts index 8664edc..f06577b 100644 --- a/src/api/admin/AdminStickerService.ts +++ b/src/api/admin/AdminStickerService.ts @@ -1,4 +1,4 @@ -import { Context, GET, Path, PathParam, POST, Security, ServiceContext } from "typescript-rest"; +import { Context, GET, Path, PathParam, POST, DELETE, Security, ServiceContext } from "typescript-rest"; import StickerPack from "../../db/models/StickerPack"; import { ApiError } from "../ApiError"; import { DimensionStickerService, MemoryStickerPack } from "../dimension/DimensionStickerService"; @@ -49,6 +49,19 @@ export class AdminStickerService { return {}; // 200 OK } + @DELETE + @Path("packs/:id") + @Security([ROLE_ADMIN]) + public async removePack(@PathParam("id") packId: number): Promise { + const pack = await StickerPack.findByPk(packId); + if (!pack) throw new ApiError(404, "Sticker pack not found"); + + await pack.destroy(); + Cache.for(CACHE_STICKERS).clear(); + + return {}; // 200 OK + } + @POST @Path("packs/import/telegram") @Security([ROLE_USER, ROLE_ADMIN]) diff --git a/web/app/admin/sticker-packs/sticker-packs.component.html b/web/app/admin/sticker-packs/sticker-packs.component.html index f6c9ca7..bd1cc19 100644 --- a/web/app/admin/sticker-packs/sticker-packs.component.html +++ b/web/app/admin/sticker-packs/sticker-packs.component.html @@ -52,10 +52,13 @@ + + + - \ No newline at end of file + diff --git a/web/app/admin/sticker-packs/sticker-packs.component.scss b/web/app/admin/sticker-packs/sticker-packs.component.scss index d92d2a2..9e19650 100644 --- a/web/app/admin/sticker-packs/sticker-packs.component.scss +++ b/web/app/admin/sticker-packs/sticker-packs.component.scss @@ -7,6 +7,11 @@ tr td:last-child { vertical-align: text-bottom; } +.removeButton { + cursor: pointer; + vertical-align: text-bottom; +} + .telegram-import { margin-bottom: 15px; } diff --git a/web/app/admin/sticker-packs/sticker-packs.component.ts b/web/app/admin/sticker-packs/sticker-packs.component.ts index 8078833..e6fbf78 100644 --- a/web/app/admin/sticker-packs/sticker-packs.component.ts +++ b/web/app/admin/sticker-packs/sticker-packs.component.ts @@ -68,4 +68,23 @@ export class AdminStickerPacksComponent implements OnInit { this.toaster.pop("error", "Error importing sticker pack"); }); } + + public removePack(pack: FE_StickerPack) { + //console.log(this.packs) + //console.log(pack) + this.isUpdating = true; + this.adminStickers.removePack(pack.id).then(() => { + for (let i = 0; i < this.packs.length; ++i) + if (this.packs[i].id === pack.id) { + this.packs.splice(i, 1); + break; + } + this.isUpdating = false; + this.toaster.pop("success", "Sticker pack removed"); + }).catch(err => { + console.error(err); + this.isUpdating = false; + this.toaster.pop("error", "Error removing sticker pack"); + }); + } } diff --git a/web/app/shared/services/admin/admin-stickers-api-service.ts b/web/app/shared/services/admin/admin-stickers-api-service.ts index b4ffdb0..b5f2c54 100644 --- a/web/app/shared/services/admin/admin-stickers-api-service.ts +++ b/web/app/shared/services/admin/admin-stickers-api-service.ts @@ -20,4 +20,8 @@ export class AdminStickersApiService extends AuthedApi { public importFromTelegram(packUrl: string): Promise { return this.authedPost("/api/v1/dimension/admin/stickers/packs/import/telegram", {packUrl: packUrl}).toPromise(); } + + public removePack(packId: number): Promise { + return this.authedDelete("/api/v1/dimension/admin/stickers/packs/" + packId).toPromise(); + } }