39 lines
902 B
TypeScript
39 lines
902 B
TypeScript
import useDatabase from '~/composables/useDatabase';
|
|
|
|
export interface Comment
|
|
{
|
|
file: number;
|
|
user_id: number;
|
|
sequence: number;
|
|
position: number;
|
|
length: number;
|
|
content: string;
|
|
}
|
|
export default defineEventHandler(async (e) => {
|
|
const project = getRouterParam(e, "projectId");
|
|
const file = getRouterParam(e, "fileId");
|
|
const query = getQuery(e);
|
|
|
|
if(!project)
|
|
{
|
|
setResponseStatus(e, 404);
|
|
return;
|
|
}
|
|
|
|
const where = ["project = $project", "file = $file"];
|
|
const criteria: Record<string, any> = { $project: project, $file: file };
|
|
|
|
if(where.length > 1)
|
|
{
|
|
const db = useDatabase();
|
|
|
|
const content = db.query(`SELECT * FROM explorer_comments WHERE ${where.join(" and ")}`).all(criteria) as Comment[];
|
|
|
|
if(content.length > 0)
|
|
{
|
|
return content;
|
|
}
|
|
}
|
|
|
|
setResponseStatus(e, 404);
|
|
}); |