mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-09-08 15:47:37 +08:00
refactor(types): result types
move to shared types (#4774) add types to ape client (#4786)
This commit is contained in:
parent
15c697802d
commit
e31613533c
6 changed files with 36 additions and 7 deletions
|
@ -621,7 +621,9 @@ export async function addResult(
|
|||
);
|
||||
}
|
||||
|
||||
const data: AddResultData = {
|
||||
const data: Omit<SharedTypes.PostResultResponse, "insertedId"> & {
|
||||
insertedId: ObjectId;
|
||||
} = {
|
||||
isPb,
|
||||
tagPbs,
|
||||
insertedId: addedResult.insertedId,
|
||||
|
|
|
@ -5,25 +5,30 @@ export default class Results {
|
|||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
async get(offset?: number): Ape.EndpointResponse {
|
||||
async get(
|
||||
offset?: number
|
||||
): Ape.EndpointResponse<SharedTypes.DBResult<SharedTypes.Config.Mode>[]> {
|
||||
return await this.httpClient.get(BASE_PATH, { searchQuery: { offset } });
|
||||
}
|
||||
|
||||
async save(
|
||||
result: SharedTypes.Result<SharedTypes.Config.Mode>
|
||||
): Ape.EndpointResponse {
|
||||
): Ape.EndpointResponse<Ape.Results.PostResult> {
|
||||
return await this.httpClient.post(BASE_PATH, {
|
||||
payload: { result },
|
||||
});
|
||||
}
|
||||
|
||||
async updateTags(resultId: string, tagIds: string[]): Ape.EndpointResponse {
|
||||
async updateTags(
|
||||
resultId: string,
|
||||
tagIds: string[]
|
||||
): Ape.EndpointResponse<Ape.Results.PatchResult> {
|
||||
return await this.httpClient.patch(`${BASE_PATH}/tags`, {
|
||||
payload: { resultId, tagIds },
|
||||
});
|
||||
}
|
||||
|
||||
async deleteAll(): Ape.EndpointResponse {
|
||||
async deleteAll(): Ape.EndpointResponse<Ape.Results.DeleteAll> {
|
||||
return await this.httpClient.delete(BASE_PATH);
|
||||
}
|
||||
}
|
||||
|
|
9
frontend/src/ts/ape/types/results.d.ts
vendored
Normal file
9
frontend/src/ts/ape/types/results.d.ts
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
// for some reason when using the dot notaion, the types are not being recognized as used
|
||||
declare namespace Ape.Results {
|
||||
type PostResult = SharedTypes.PostResultResponse;
|
||||
type PatchResult = {
|
||||
tagPbs: string[];
|
||||
};
|
||||
type DeleteAll = null;
|
||||
}
|
|
@ -149,7 +149,8 @@ $("#resultEditTagsPanelWrapper .confirmButton").on("click", async () => {
|
|||
);
|
||||
}
|
||||
|
||||
const responseTagPbs = response.data.tagPbs;
|
||||
//can do this because the response will not be null if the status is 200
|
||||
const responseTagPbs = response.data?.tagPbs ?? [];
|
||||
|
||||
Notifications.add("Tags updated", 1, {
|
||||
duration: 2,
|
||||
|
|
|
@ -1198,7 +1198,7 @@ async function saveResult(
|
|||
|
||||
$("#result .stats .tags .editTagsButton").attr(
|
||||
"result-id",
|
||||
response.data.insertedId
|
||||
response.data?.insertedId as string //if status is 200 then response.data is not null or undefined
|
||||
);
|
||||
$("#result .stats .tags .editTagsButton").removeClass("invisible");
|
||||
|
||||
|
|
12
shared-types/types.d.ts
vendored
12
shared-types/types.d.ts
vendored
|
@ -454,4 +454,16 @@ declare namespace SharedTypes {
|
|||
badgeId: number | null;
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
type PostResultResponse = {
|
||||
isPb: boolean;
|
||||
tagPbs: string[];
|
||||
insertedId: string;
|
||||
dailyLeaderboardRank?: number;
|
||||
weeklyXpLeaderboardRank?: number;
|
||||
xp: number;
|
||||
dailyXpBonus: boolean;
|
||||
xpBreakdown: Record<string, number>;
|
||||
streak: number;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue