General Goal/Milestone Endpoints

Fixes #657
This commit is contained in:
zkldi
2022-03-21 21:25:21 +00:00
parent a2c35a80c4
commit d3d58fffcf
3 changed files with 3619 additions and 1729 deletions
+1 -1
View File
@@ -82,7 +82,7 @@
"rimraf": "3.0.2",
"safe-json-stringify": "1.2.0",
"seq-logging": "1.1.1",
"tachi-common": "0.6.11",
"tachi-common": "0.7.0",
"ts-node": "10.4.0",
"tsconfig-paths": "3.12.0",
"typescript": "4.5.5",
+3596 -1716
View File
File diff suppressed because it is too large Load Diff
@@ -48,6 +48,7 @@ export async function UpdateGoalsForUser(
const importInfo = [];
const bulkWrite = [];
const webhookEventContent = [];
for (const ret of returns) {
if (!ret) {
@@ -56,6 +57,10 @@ export async function UpdateGoalsForUser(
importInfo.push(ret.import);
bulkWrite.push(ret.bwrite);
if (ret.webhookEvent) {
webhookEventContent.push(ret.webhookEvent);
}
}
if (bulkWrite.length === 0) {
@@ -64,6 +69,13 @@ export async function UpdateGoalsForUser(
return [];
}
if (webhookEventContent.length !== 0) {
await EmitWebhookEvent({
type: "goals-achieved/v1",
content: { goals: webhookEventContent, userID },
});
}
await db["user-goals"].bulkWrite(bulkWrite, { ordered: false });
return importInfo;
@@ -109,19 +121,16 @@ export async function ProcessGoal(
achieved: userGoal.achieved,
};
let webhookEvent = null;
// if this is a newly-achieved goal
if (res.achieved && !userGoal.achieved) {
EmitWebhookEvent({
type: "goal-achieved/v1",
content: {
userID,
goalID: goal.goalID,
old: oldData,
new: newData,
game: goal.game,
playtype: goal.playtype,
},
});
webhookEvent = {
goalID: goal.goalID,
old: oldData,
new: newData,
game: goal.game,
playtype: goal.playtype,
};
}
const bulkWrite = {
@@ -147,6 +156,7 @@ export async function ProcessGoal(
old: oldData,
new: newData,
},
webhookEvent,
};
}
@@ -164,7 +174,7 @@ export async function GetRelevantGoals(
chartIDs: Set<string>,
logger: KtLogger
): Promise<{ goals: GoalDocument[]; userGoalsMap: Map<string, UserGoalDocument> }> {
const userGoals = await db["user-goals"].find({ game, userID });
const userGoals = await db["user-goals"].find({ game, userID }, { projectID: true });
logger.verbose(`Found user has ${userGoals.length} goals.`);