Skip to content
Snippets Groups Projects
Commit 1ebd42f3 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #be sketch shot routes

parent b7b3ae18
No related branches found
No related tags found
No related merge requests found
...@@ -5,11 +5,45 @@ import { connection } from "./db"; ...@@ -5,11 +5,45 @@ import { connection } from "./db";
// NOTE: see https://www.npmjs.com/package/fastify-plugin for TS plugin definition // NOTE: see https://www.npmjs.com/package/fastify-plugin for TS plugin definition
const ParamsSchema = Type.Object({ const GameParamsSchema = Type.Object({
game_id: Type.String({ format: "uuid" }), game_id: Type.String({ format: "uuid" }),
}); });
type ParamsType = Static<typeof ParamsSchema>; type GameParamsType = Static<typeof GameParamsSchema>;
const ClueParamsSchema = Type.Object({
game_id: Type.String({ format: "uuid" }),
clue_id: Type.String({ format: "uuid" }),
});
type ClueParamsType = Static<typeof ClueParamsSchema>;
const ClueSchema = Type.Object({
id: Type.Readonly(Type.String({ format: "uuid" })),
game_id: Type.Readonly(Type.String({ format: "uuid" })),
word_id: Type.Readonly(Type.String({ format: "uuid" })),
began_at: Type.Optional(Type.String({ format: "date-time" })),
ended_at: Type.Optional(Type.String({ format: "date-time" })),
});
const CluePostSchema = Type.Pick(ClueSchema, ["game_id", "word_id"]);
const CluePatchSchema = Type.Pick(ClueSchema, ["began_at", "ended_at"]);
type ClueType = Static<typeof ClueSchema>;
const ShotSchema = Type.Object({
id: Type.Readonly(Type.String({ format: "uuid" })),
game_id: Type.Readonly(Type.String({ format: "uuid" })),
clue_id: Type.Optional(Type.Readonly(Type.String({ format: "uuid" }))),
began_at: Type.String({ format: "date-time" }),
ended_at: Type.String({ format: "date-time" }),
typed: Type.String(),
final: Type.String(),
});
const ShotPostSchema = Type.Omit(ShotSchema, ["id"]);
type ShotType = Static<typeof ShotSchema>;
const GameSchema = Type.Object({ const GameSchema = Type.Object({
id: Type.Readonly(Type.String({ format: "uuid" })), id: Type.Readonly(Type.String({ format: "uuid" })),
...@@ -58,13 +92,13 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => { ...@@ -58,13 +92,13 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
}); });
fastify.route<{ fastify.route<{
Params: ParamsType; Params: GameParamsType;
Reply: GameType; Reply: GameType;
}>({ }>({
method: "GET", method: "GET",
url: "/games/:game_id", url: "/games/:game_id",
schema: { schema: {
params: ParamsSchema, params: GameParamsSchema,
response: { response: {
200: GameSchema, 200: GameSchema,
404: {}, // TODO: JSend error 404: {}, // TODO: JSend error
...@@ -103,14 +137,14 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => { ...@@ -103,14 +137,14 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
}); });
fastify.route<{ fastify.route<{
Params: ParamsType; Params: GameParamsType;
Body: Static<typeof GamePatchSchema>; Body: Static<typeof GamePatchSchema>;
Reply: GameType; Reply: GameType;
}>({ }>({
method: "PATCH", method: "PATCH",
url: "/games/:game_id", url: "/games/:game_id",
schema: { schema: {
params: ParamsSchema, params: GameParamsSchema,
body: GamePatchSchema, body: GamePatchSchema,
response: { response: {
200: GameSchema, 200: GameSchema,
...@@ -131,6 +165,57 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => { ...@@ -131,6 +165,57 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
}, },
}); });
fastify.route<{
Params: Static<typeof GameParamsSchema>;
Body: Static<typeof CluePostSchema>;
Reply: ClueType;
}>({
method: "POST",
url: "/games/:game_id/clues",
schema: {
params: GameParamsSchema,
body: CluePostSchema,
response: {
200: ClueSchema,
},
},
handler: async (request, reply) => {},
});
fastify.route<{
Params: Static<typeof ClueParamsSchema>;
Body: Static<typeof CluePatchSchema>;
Reply: ClueType;
}>({
method: "PATCH",
url: "/games/:game_id/clues/:clue_id",
schema: {
params: ClueParamsSchema,
body: CluePatchSchema,
response: {
200: ClueSchema,
},
},
handler: async (request, reply) => {},
});
fastify.route<{
Params: Static<typeof GameParamsSchema>;
Body: Static<typeof ShotPostSchema>;
Reply: ShotType;
}>({
method: "POST",
url: "/games/:game_id/shots",
schema: {
params: GameParamsSchema,
body: ShotPostSchema,
response: {
200: ShotSchema,
},
},
handler: async (request, reply) => {},
});
next(); next();
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment