fix: revise questions management
This commit is contained in:
parent
aba7199df7
commit
f9d7e0398d
|
|
@ -11,6 +11,7 @@ import authInfo from "../../middlewares/authInfo";
|
||||||
import checkPermission from "../../middlewares/checkPermission";
|
import checkPermission from "../../middlewares/checkPermission";
|
||||||
import { aspects } from "../../drizzle/schema/aspects";
|
import { aspects } from "../../drizzle/schema/aspects";
|
||||||
import { subAspects } from "../../drizzle/schema/subAspects";
|
import { subAspects } from "../../drizzle/schema/subAspects";
|
||||||
|
import { notFound } from "../../errors/DashboardError";
|
||||||
|
|
||||||
export const questionFormSchema = z.object({
|
export const questionFormSchema = z.object({
|
||||||
subAspectId: z.string().min(1).max(255),
|
subAspectId: z.string().min(1).max(255),
|
||||||
|
|
@ -19,9 +20,9 @@ export const questionFormSchema = z.object({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const questionUpdateSchema = questionFormSchema.extend({
|
export const questionUpdateSchema = questionFormSchema.extend({
|
||||||
question: z.string().min(1).max(255).optional().or(z.literal("")),
|
question: z.string().min(1).max(255).or(z.literal("")),
|
||||||
subAspectiD: z.string().min(1).max(255).optional().or(z.literal("")),
|
subAspectId: z.string().min(1).max(255).or(z.literal("")),
|
||||||
needFile: z.boolean().default(false).optional().or(z.boolean()),
|
needFile: z.boolean().default(false).or(z.boolean()),
|
||||||
});
|
});
|
||||||
|
|
||||||
const questionsRoute = new Hono<HonoEnv>()
|
const questionsRoute = new Hono<HonoEnv>()
|
||||||
|
|
@ -30,7 +31,7 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
* Get All Questions (With Metadata)
|
* Get All Questions (With Metadata)
|
||||||
*
|
*
|
||||||
* Query params:
|
* Query params:
|
||||||
* - includeTrashed: boolean (default: false)\
|
* - includeTrashed: boolean (default: false)
|
||||||
* - withMetadata: boolean
|
* - withMetadata: boolean
|
||||||
*/
|
*/
|
||||||
.get(
|
.get(
|
||||||
|
|
@ -79,10 +80,6 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
includeTrashed ? undefined : isNull(questions.deletedAt),
|
includeTrashed ? undefined : isNull(questions.deletedAt),
|
||||||
q
|
q
|
||||||
? or(
|
? or(
|
||||||
ilike(subAspects.aspectId, q),
|
|
||||||
ilike(questions.subAspectId, q),
|
|
||||||
ilike(questions.question, q),
|
|
||||||
ilike(questions.needFile, q),
|
|
||||||
ilike(questions.createdAt, q),
|
ilike(questions.createdAt, q),
|
||||||
ilike(questions.updatedAt, q),
|
ilike(questions.updatedAt, q),
|
||||||
ilike(questions.deletedAt, q),
|
ilike(questions.deletedAt, q),
|
||||||
|
|
@ -107,7 +104,13 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// get user by id
|
/**
|
||||||
|
* Get Question by ID
|
||||||
|
*
|
||||||
|
* Query params:
|
||||||
|
* - id: string
|
||||||
|
* - includeTrashed: boolean (default: false)
|
||||||
|
*/
|
||||||
.get(
|
.get(
|
||||||
"/:id",
|
"/:id",
|
||||||
checkPermission("questions.readAll"),
|
checkPermission("questions.readAll"),
|
||||||
|
|
@ -149,14 +152,19 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
message: "The question does not exists",
|
message: "The question does not exists",
|
||||||
});
|
});
|
||||||
|
|
||||||
const userData = {
|
const questionData = {
|
||||||
...queryResult[0],
|
...queryResult[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
return c.json(userData);
|
return c.json(questionData);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// create question
|
/**
|
||||||
|
* Create Question
|
||||||
|
*
|
||||||
|
* JSON:
|
||||||
|
* - questionFormSchema: object
|
||||||
|
*/
|
||||||
.post(
|
.post(
|
||||||
"/",
|
"/",
|
||||||
checkPermission("questions.create"),
|
checkPermission("questions.create"),
|
||||||
|
|
@ -182,8 +190,12 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
/**
|
||||||
//update question
|
* Update Question
|
||||||
|
*
|
||||||
|
* JSON:
|
||||||
|
* - questionUpdateSchema: object
|
||||||
|
*/
|
||||||
.patch(
|
.patch(
|
||||||
"/:id",
|
"/:id",
|
||||||
checkPermission("questions.update"),
|
checkPermission("questions.update"),
|
||||||
|
|
@ -197,7 +209,7 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
.from(questions)
|
.from(questions)
|
||||||
.where(and(eq(questions.id, questionId), isNull(questions.deletedAt)));
|
.where(and(eq(questions.id, questionId), isNull(questions.deletedAt)));
|
||||||
|
|
||||||
if (!question[0]) return c.notFound();
|
if (!question[0]) throw notFound();
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(questions)
|
.update(questions)
|
||||||
|
|
@ -212,8 +224,13 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
/**
|
||||||
//delete user
|
* Delete Question
|
||||||
|
*
|
||||||
|
* Query params:
|
||||||
|
* - id: string
|
||||||
|
* - skipTrash: string (default: false)
|
||||||
|
*/
|
||||||
.delete(
|
.delete(
|
||||||
"/:id",
|
"/:id",
|
||||||
checkPermission("questions.delete"),
|
checkPermission("questions.delete"),
|
||||||
|
|
@ -259,8 +276,12 @@ const questionsRoute = new Hono<HonoEnv>()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
/**
|
||||||
// undo delete
|
* Restore Question
|
||||||
|
*
|
||||||
|
* Query params:
|
||||||
|
* - id: string
|
||||||
|
*/
|
||||||
.patch("/restore/:id",
|
.patch("/restore/:id",
|
||||||
checkPermission("questions.restore"),
|
checkPermission("questions.restore"),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user