Refactor /me routes
This commit is contained in:
+25
-32
@@ -458,6 +458,7 @@ export const app = new Elysia()
|
|||||||
|
|
||||||
// ACCOUNTS
|
// ACCOUNTS
|
||||||
.group("/accounts", (app) => app
|
.group("/accounts", (app) => app
|
||||||
|
// TODO: for added security, could enforce bot or admin only access
|
||||||
.get("/:id/stats", async ({ params: { id } }) => {
|
.get("/:id/stats", async ({ params: { id } }) => {
|
||||||
const stats = await s.Accounts.stats(id);
|
const stats = await s.Accounts.stats(id);
|
||||||
if (!stats) throw new NotFoundError("Account stats not found");
|
if (!stats) throw new NotFoundError("Account stats not found");
|
||||||
@@ -465,13 +466,6 @@ export const app = new Elysia()
|
|||||||
}, {
|
}, {
|
||||||
params: t.Object({ id: t.String() })
|
params: t.Object({ id: t.String() })
|
||||||
})
|
})
|
||||||
.guard({ auth: true }, (app) => app
|
|
||||||
.get("/me/stats", async ({ accountId }) => {
|
|
||||||
const stats = await s.Accounts.stats(accountId);
|
|
||||||
if (!stats) throw new NotFoundError("Account stats not found");
|
|
||||||
return stats;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.guard({ authAdmin: true }, (app) => app
|
.guard({ authAdmin: true }, (app) => app
|
||||||
.get("/:id", async ({ params: { id } }) => {
|
.get("/:id", async ({ params: { id } }) => {
|
||||||
const account = await s.Accounts.get(id);
|
const account = await s.Accounts.get(id);
|
||||||
@@ -481,12 +475,13 @@ export const app = new Elysia()
|
|||||||
params: t.Object({ id: t.String() })
|
params: t.Object({ id: t.String() })
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
.group("/me", { auth: true }, (app) => app
|
||||||
|
.get("/stats", async ({ accountId }) => {
|
||||||
// ASSESSMENTS
|
const stats = await s.Accounts.stats(accountId);
|
||||||
.group("/assessments", (app) => app
|
if (!stats) throw new NotFoundError("Account stats not found");
|
||||||
.guard({ auth: true }, (app) => app
|
return stats;
|
||||||
.post("/me", async ({ body: { player, activityPerformances }, accountId }) => {
|
})
|
||||||
|
.post("/assessments", async ({ body: { player, activityPerformances }, accountId }) => {
|
||||||
return await s.Assessments.create(player, activityPerformances, accountId);
|
return await s.Assessments.create(player, activityPerformances, accountId);
|
||||||
}, {
|
}, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
@@ -494,17 +489,30 @@ export const app = new Elysia()
|
|||||||
activityPerformances: t.Array(ActivityPerformanceSchema)
|
activityPerformances: t.Array(ActivityPerformanceSchema)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.get("/me", async ({ accountId }) => {
|
.get("/assessments", async ({ accountId }) => {
|
||||||
return await s.Assessments.list({ filter: { accountId } });
|
return await s.Assessments.list({ filter: { accountId } });
|
||||||
})
|
})
|
||||||
.delete("/me/:id", async ({ params: { id }, accountId }) => {
|
.delete("/assessments/:id", async ({ params: { id }, accountId }) => {
|
||||||
const deleted = await s.Assessments.delete(id, accountId);
|
const deleted = await s.Assessments.delete(id, accountId);
|
||||||
if (!deleted) throw new NotFoundError("Assessment not found");
|
if (!deleted) throw new NotFoundError("Assessment not found");
|
||||||
}, {
|
}, {
|
||||||
params: t.Object({ id: t.String() })
|
params: t.Object({ id: t.String() })
|
||||||
})
|
})
|
||||||
|
.post("/verifications", async ({ body: { assessmentId, activityVideoUrls }, accountId }) => {
|
||||||
|
const requested = await s.Verifications.request(assessmentId, accountId, activityVideoUrls);
|
||||||
|
if (!requested) throw new NotFoundError("Assessment not found");
|
||||||
|
return requested;
|
||||||
|
}, {
|
||||||
|
body: t.Object({
|
||||||
|
assessmentId: t.String(),
|
||||||
|
activityVideoUrls: ActivityVideosSchema,
|
||||||
|
})
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.guard({ authAdmin: true }, (app) => app
|
)
|
||||||
|
|
||||||
|
// ASSESSMENTS
|
||||||
|
.group("/assessments", { authAdmin: true }, (app) => app
|
||||||
.post("/", async ({ body: { player, activityPerformances, id } }) => {
|
.post("/", async ({ body: { player, activityPerformances, id } }) => {
|
||||||
await s.Assessments.create(player, activityPerformances, id);
|
await s.Assessments.create(player, activityPerformances, id);
|
||||||
}, {
|
}, {
|
||||||
@@ -525,23 +533,9 @@ export const app = new Elysia()
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
// VERIFICATIONS
|
// VERIFICATIONS
|
||||||
.group("/verifications", (app) => app
|
.group("/verifications", { authAdmin: true }, (app) => app
|
||||||
.guard({ auth: true }, (app) => app
|
|
||||||
.post("/me", async ({ body: { assessmentId, activityVideoUrls }, accountId }) => {
|
|
||||||
const requested = await s.Verifications.request(assessmentId, accountId, activityVideoUrls);
|
|
||||||
if (!requested) throw new NotFoundError("Assessment not found");
|
|
||||||
return requested;
|
|
||||||
}, {
|
|
||||||
body: t.Object({
|
|
||||||
assessmentId: t.String(),
|
|
||||||
activityVideoUrls: ActivityVideosSchema,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.guard({ authAdmin: true }, (app) => app
|
|
||||||
.get("/", async ({ query }) => {
|
.get("/", async ({ query }) => {
|
||||||
return await s.Verifications.list({
|
return await s.Verifications.list({
|
||||||
filter: { status: query.status },
|
filter: { status: query.status },
|
||||||
@@ -592,7 +586,6 @@ export const app = new Elysia()
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
// WEBHOOKS
|
// WEBHOOKS
|
||||||
.post("/webhooks/printful", async ({ body, query }) => {
|
.post("/webhooks/printful", async ({ body, query }) => {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
import { api } from "$lib/api";
|
import { api } from "$lib/api";
|
||||||
|
|
||||||
type AssessmentRow = NonNullable<
|
type AssessmentRow = NonNullable<
|
||||||
Awaited<ReturnType<typeof api.assessments.me.get>>["data"]
|
Awaited<ReturnType<typeof api.accounts.me.assessments.get>>["data"]
|
||||||
>[number];
|
>[number];
|
||||||
|
|
||||||
interface CalcData {
|
interface CalcData {
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
loading = true;
|
loading = true;
|
||||||
loadError = null;
|
loadError = null;
|
||||||
try {
|
try {
|
||||||
const res = await api.assessments.me.get();
|
const res = await api.accounts.me.assessments.get();
|
||||||
if (res.error) throw res.error;
|
if (res.error) throw res.error;
|
||||||
calculations = (res.data ?? []).map(assessmentToCalc);
|
calculations = (res.data ?? []).map(assessmentToCalc);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -135,7 +135,7 @@
|
|||||||
});
|
});
|
||||||
if (res.error) throw res.error;
|
if (res.error) throw res.error;
|
||||||
} else {
|
} else {
|
||||||
const res = await api.assessments.me.post({
|
const res = await api.accounts.me.assessments.post({
|
||||||
player: calculation.player,
|
player: calculation.player,
|
||||||
activityPerformances: calculation.activityPerformances,
|
activityPerformances: calculation.activityPerformances,
|
||||||
});
|
});
|
||||||
@@ -162,7 +162,7 @@
|
|||||||
calculation.deleting = true;
|
calculation.deleting = true;
|
||||||
calculation.deleteError = undefined;
|
calculation.deleteError = undefined;
|
||||||
try {
|
try {
|
||||||
const res = await api.assessments.me({ id: calculation.id }).delete();
|
const res = await api.accounts.me.assessments({ id: calculation.id }).delete();
|
||||||
if (res.error) throw res.error;
|
if (res.error) throw res.error;
|
||||||
calculations.splice(index, 1);
|
calculations.splice(index, 1);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user