From 65120db1f099c3bf8b72277b56acc97ac9106a93 Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 7 Feb 2024 19:05:47 +0100 Subject: [PATCH] refactor(types): PSA types move to shared types (#4774) add types to ape client (#4786) --- backend/src/dal/psa.ts | 6 ++++-- backend/src/types/types.d.ts | 6 ------ frontend/src/ts/ape/endpoints/psas.ts | 2 +- frontend/src/ts/elements/psa.ts | 4 ++-- frontend/src/ts/types/types.d.ts | 8 -------- shared-types/types.d.ts | 8 ++++++++ 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/backend/src/dal/psa.ts b/backend/src/dal/psa.ts index e1d202f69..3f7ace3b7 100644 --- a/backend/src/dal/psa.ts +++ b/backend/src/dal/psa.ts @@ -1,5 +1,7 @@ import * as db from "../init/db"; -export async function get(): Promise { - return await db.collection("psa").find().toArray(); +type PSA = MonkeyTypes.WithObjectId; + +export async function get(): Promise { + return await db.collection("psa").find().toArray(); } diff --git a/backend/src/types/types.d.ts b/backend/src/types/types.d.ts index 60edbac3d..88531ab10 100644 --- a/backend/src/types/types.d.ts +++ b/backend/src/types/types.d.ts @@ -185,12 +185,6 @@ declare namespace MonkeyTypes { approved: boolean; } - interface PSA { - sticky?: boolean; - message: string; - level?: number; - } - type ReportTypes = "quote" | "user"; interface Report { diff --git a/frontend/src/ts/ape/endpoints/psas.ts b/frontend/src/ts/ape/endpoints/psas.ts index 1dffc1560..55b9989ea 100644 --- a/frontend/src/ts/ape/endpoints/psas.ts +++ b/frontend/src/ts/ape/endpoints/psas.ts @@ -5,7 +5,7 @@ export default class Psas { this.httpClient = httpClient; } - async get(): Ape.EndpointResponse { + async get(): Ape.EndpointResponse { return await this.httpClient.get(BASE_PATH); } } diff --git a/frontend/src/ts/elements/psa.ts b/frontend/src/ts/elements/psa.ts index 603132a8a..bc7c7dfa1 100644 --- a/frontend/src/ts/elements/psa.ts +++ b/frontend/src/ts/elements/psa.ts @@ -18,7 +18,7 @@ function setMemory(id: string): void { window.localStorage.setItem("confirmedPSAs", JSON.stringify(list)); } -async function getLatest(): Promise { +async function getLatest(): Promise { const response = await Ape.psas.get(); if (response.status === 500) { @@ -54,7 +54,7 @@ async function getLatest(): Promise { } else if (response.status !== 200) { return null; } - return response.data as MonkeyTypes.PSA[]; + return response.data; } export async function show(): Promise { diff --git a/frontend/src/ts/types/types.d.ts b/frontend/src/ts/types/types.d.ts index 7f4d4daff..f80330903 100644 --- a/frontend/src/ts/types/types.d.ts +++ b/frontend/src/ts/types/types.d.ts @@ -647,14 +647,6 @@ declare namespace MonkeyTypes { textSplit?: string[]; } - interface PSA { - sticky?: boolean; - message: string; - _id: string; - level?: number; - date?: number; - } - interface ThemeColors { bg: string; main: string; diff --git a/shared-types/types.d.ts b/shared-types/types.d.ts index d33aa42c0..5234af4c9 100644 --- a/shared-types/types.d.ts +++ b/shared-types/types.d.ts @@ -318,4 +318,12 @@ declare namespace SharedTypes { none?: boolean; } & Record; } + + interface PSA { + _id: string; + message: string; + sticky?: boolean; + level?: number; + date?: number; + } }