mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-30 14:24:55 -05:00
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { createRouter } from "pages/api/trpc/[trpc]";
|
|
import { throwIfNotLoggedIn } from "utils/api";
|
|
import { suggestionFullSchema } from "utils/validators/suggestion";
|
|
import { voteSchema, votesSchema } from "utils/validators/votes";
|
|
import { vouchSchema } from "utils/validators/vouch";
|
|
import service from "./service";
|
|
|
|
const plusApi = createRouter()
|
|
.query("suggestions", {
|
|
resolve() {
|
|
return service.getSuggestions();
|
|
},
|
|
})
|
|
.query("statuses", {
|
|
resolve() {
|
|
return service.getPlusStatuses();
|
|
},
|
|
})
|
|
.query("usersForVoting", {
|
|
resolve({ ctx }) {
|
|
const user = throwIfNotLoggedIn(ctx.user);
|
|
return service.getUsersForVoting(user.id);
|
|
},
|
|
})
|
|
.query("votedUserScores", {
|
|
resolve({ ctx }) {
|
|
const user = throwIfNotLoggedIn(ctx.user);
|
|
return service.votedUserScores(user.id);
|
|
},
|
|
})
|
|
.query("votingProgress", {
|
|
resolve() {
|
|
return service.votingProgress();
|
|
},
|
|
})
|
|
.mutation("suggestion", {
|
|
input: suggestionFullSchema,
|
|
resolve({ input, ctx }) {
|
|
const user = throwIfNotLoggedIn(ctx.user);
|
|
return service.addSuggestion({ input, userId: user.id });
|
|
},
|
|
})
|
|
.mutation("vouch", {
|
|
input: vouchSchema,
|
|
resolve({ input, ctx }) {
|
|
const user = throwIfNotLoggedIn(ctx.user);
|
|
return service.addVouch({ input, userId: user.id });
|
|
},
|
|
})
|
|
.mutation("vote", {
|
|
input: votesSchema,
|
|
resolve({ input, ctx }) {
|
|
const user = throwIfNotLoggedIn(ctx.user);
|
|
return service.addVotes({ input, userId: user.id });
|
|
},
|
|
})
|
|
.mutation("editVote", {
|
|
input: voteSchema,
|
|
resolve({ input, ctx }) {
|
|
const user = throwIfNotLoggedIn(ctx.user);
|
|
return service.editVote({ input, userId: user.id });
|
|
},
|
|
})
|
|
.mutation("endVoting", {
|
|
resolve({ ctx }) {
|
|
const user = throwIfNotLoggedIn(ctx.user);
|
|
return service.endVoting(user.id);
|
|
},
|
|
});
|
|
export default plusApi;
|