From bec7e14aba9b09bf06467a353fa9f83f738dcb80 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 13 Apr 2022 21:53:48 +0100 Subject: [PATCH] Update "abs" to "absolute" for goal criteria. --- server/package.json | 2 +- server/pnpm-lock.yaml | 8 ++++---- server/src/external/mongo/schemas.ts | 4 ++-- server/src/lib/targets/goal-utils.ts | 4 ++-- server/src/lib/targets/goals.ts | 4 ++-- .../games/_game/_playtype/targets/goals/router.test.ts | 8 ++++---- .../_userID/games/_game/_playtype/targets/goals/router.ts | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/server/package.json b/server/package.json index 63acc6978..51869c0cd 100644 --- a/server/package.json +++ b/server/package.json @@ -84,7 +84,7 @@ "rimraf": "3.0.2", "safe-json-stringify": "1.2.0", "seq-logging": "1.1.1", - "tachi-common": "0.7.13", + "tachi-common": "0.7.14", "ts-node": "10.4.0", "tsconfig-paths": "3.12.0", "typescript": "4.5.5", diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index 46faf9cec..b451adbaa 100644 --- a/server/pnpm-lock.yaml +++ b/server/pnpm-lock.yaml @@ -65,7 +65,7 @@ specifiers: safe-json-stringify: 1.2.0 seq-logging: 1.1.1 supertest: 6.2.2 - tachi-common: 0.7.13 + tachi-common: 0.7.14 tap: 15.1.6 ts-node: 10.4.0 tsconfig-paths: 3.12.0 @@ -112,7 +112,7 @@ dependencies: rimraf: 3.0.2 safe-json-stringify: 1.2.0 seq-logging: 1.1.1 - tachi-common: 0.7.13 + tachi-common: 0.7.14 ts-node: 10.4.0_2615db9039ce432b4abf2fc39ef336ec tsconfig-paths: 3.12.0 typescript: 4.5.5 @@ -5363,8 +5363,8 @@ packages: engines: {node: '>= 0.4'} dev: true - /tachi-common/0.7.13: - resolution: {integrity: sha512-r0pB7FO6QZ7j16jR0YgMzojbGxo03uS+mDGrD59dpL0tbN2V7fR6vLx+mmWELFBqrDIjcOJu2AOTkz7fPYL3fA==} + /tachi-common/0.7.14: + resolution: {integrity: sha512-RZfmSvCrITGm3jClZZc4JJAJwo6lUU+Wkq2+PAQh7gHdlR5OjVlTNDQr67F3F2KTagz6Sw4y1BDKw78j2aPl8Q==} dependencies: '@types/mongodb': 3.6.18 dev: false diff --git a/server/src/external/mongo/schemas.ts b/server/src/external/mongo/schemas.ts index a0c21fac2..1cf4ce981 100644 --- a/server/src/external/mongo/schemas.ts +++ b/server/src/external/mongo/schemas.ts @@ -634,7 +634,7 @@ export const DatabaseSchemas: Record< value: "number", }, { - mode: p.isIn("abs", "proportion"), + mode: p.isIn("absolute", "proportion"), countNum: p.isPositive, key: p.isIn( "scoreData.percent", @@ -683,7 +683,7 @@ export const DatabaseSchemas: Record< type: "all", }, { - type: p.isIn("abs", "proportion"), + type: p.isIn("absolute", "proportion"), value: p.isPositive, } ), diff --git a/server/src/lib/targets/goal-utils.ts b/server/src/lib/targets/goal-utils.ts index f19a1e5e4..37a1df25b 100644 --- a/server/src/lib/targets/goal-utils.ts +++ b/server/src/lib/targets/goal-utils.ts @@ -35,7 +35,7 @@ export async function CreateGoalTitle( return `${formattedCriteria} any chart in ${datasetName}`; } // eslint-disable-next-line no-fallthrough - case "abs": + case "absolute": switch (charts.type) { case "any": return `${formattedCriteria} ${criteria.countNum} charts`; @@ -178,7 +178,7 @@ export async function ValidateGoalChartsAndCriteria( ); } } else if ( - criteria.mode === "abs" && + criteria.mode === "absolute" && (criteria.countNum > chartCount || !Number.isInteger(criteria.countNum) || criteria.countNum < 2) diff --git a/server/src/lib/targets/goals.ts b/server/src/lib/targets/goals.ts index a72b04778..a6e1386e4 100644 --- a/server/src/lib/targets/goals.ts +++ b/server/src/lib/targets/goals.ts @@ -148,11 +148,11 @@ export async function EvaluateGoalForUser( nextBestScore ), }; - } else if (goal.criteria.mode === "abs" || goal.criteria.mode === "proportion") { + } else if (goal.criteria.mode === "absolute" || goal.criteria.mode === "proportion") { let count; // abs -> Absolute mode, such as clear 10 charts. - if (goal.criteria.mode === "abs") { + if (goal.criteria.mode === "absolute") { count = goal.criteria.countNum; } else { // proportion -> Proportional mode, the value diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.test.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.test.ts index 674d5ccfc..f716cd6b7 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.test.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.test.ts @@ -102,7 +102,7 @@ t.test("POST /api/v1/users/:userID/games/:game/:playtype/targets/add-goal", asyn }; const absModeCriteria = { - mode: "abs", + mode: "absolute", countNum: 2, }; @@ -422,7 +422,7 @@ t.test("POST /api/v1/users/:userID/games/:game/:playtype/targets/add-goal", asyn }), mkInput("abs without countNum", { criteria: { - mode: "abs", + mode: "absolute", }, charts: multiCharts, }), @@ -466,7 +466,7 @@ t.test("POST /api/v1/users/:userID/games/:game/:playtype/targets/add-goal", asyn }), mkInput("abs with countNum but charts.type == single", { criteria: { - mode: "abs", + mode: "absolute", countNum: 1, }, charts: { @@ -542,7 +542,7 @@ t.test("POST /api/v1/users/:userID/games/:game/:playtype/targets/add-goal", asyn }), mkInput("charts single but criteria not.", { criteria: { - mode: "abs", + mode: "absolute", countNum: 2, }, }), diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.ts index 228db5b01..7d41c74b4 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/targets/goals/router.ts @@ -53,7 +53,7 @@ type GoalCreationBody = Pick; * * @param criteria.key - The key for the goal to be on. This is stuff like scoreData.percent. * @param criteria.value - The value the key must be greater than for it to count as achieved. - * @param criteria.mode - "single", "abs" or "proportion". If abs or proportion, countNum + * @param criteria.mode - "single", "absolute" or "proportion". If abs or proportion, countNum * must be supplied. * @param criteria.countNum - For abs/proportion mode. Atleast N scores must achieve the * key:value condition. @@ -79,7 +79,7 @@ router.post( ), // we do proper validation on this later. value: p.gte(0), - mode: p.isIn("single", "abs", "proportion"), + mode: p.isIn("single", "absolute", "proportion"), countNum: (self, parent) => { if (parent.mode === "single") { return (