init
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
|
||||
import {
|
||||
documentChunkFilterSchema,
|
||||
documentChunksFindResultSchema,
|
||||
DocumentChunksService,
|
||||
} from '#root/services/document-chunks/document-chunks.ts';
|
||||
|
||||
const documentChunkFilterEndpoints: FastifyPluginAsyncZod = async (instance) => {
|
||||
instance.route({
|
||||
method: 'POST',
|
||||
url: '',
|
||||
schema: {
|
||||
operationId: 'POST/documents-chunk-filters',
|
||||
tags: ['document-chunks'],
|
||||
summary: 'Find document chunks',
|
||||
body: documentChunkFilterSchema,
|
||||
response: {
|
||||
200: documentChunksFindResultSchema,
|
||||
},
|
||||
},
|
||||
handler: async (req, reply) => {
|
||||
const { services } = instance;
|
||||
const documentChunksService = services.get(DocumentChunksService);
|
||||
const response = await documentChunksService.find(req.body);
|
||||
await reply.send(response);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export { documentChunkFilterEndpoints };
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
|
||||
import {
|
||||
documentFilterSchema,
|
||||
documentFindResultSchema,
|
||||
DocumentsService,
|
||||
} from '#root/services/documents/documents.ts';
|
||||
|
||||
const documentFilterEndpoints: FastifyPluginAsyncZod = async (instance) => {
|
||||
instance.route({
|
||||
method: 'POST',
|
||||
url: '',
|
||||
schema: {
|
||||
operationId: 'POST/documents-filters',
|
||||
tags: ['documents'],
|
||||
summary: 'Find documents',
|
||||
body: documentFilterSchema,
|
||||
response: {
|
||||
200: documentFindResultSchema,
|
||||
},
|
||||
},
|
||||
handler: async (req, reply) => {
|
||||
const { services } = instance;
|
||||
const documentsService = services.get(DocumentsService);
|
||||
const response = await documentsService.find(req.body);
|
||||
await reply.send(response);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export { documentFilterEndpoints };
|
||||
31
packages/server/src/endpoints/documents/documents.ts
Normal file
31
packages/server/src/endpoints/documents/documents.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
|
||||
import {
|
||||
DocumentsService,
|
||||
documentUpsertResultSchema,
|
||||
documentUpsertSchema,
|
||||
} from '#root/services/documents/documents.ts';
|
||||
|
||||
const documentEndpoints: FastifyPluginAsyncZod = async (instance) => {
|
||||
instance.route({
|
||||
method: 'POST',
|
||||
url: '',
|
||||
schema: {
|
||||
operationId: 'POST/documents',
|
||||
tags: ['documents'],
|
||||
summary: 'Upsert document',
|
||||
body: documentUpsertSchema,
|
||||
response: {
|
||||
200: documentUpsertResultSchema,
|
||||
},
|
||||
},
|
||||
handler: async (req, reply) => {
|
||||
const { services } = instance;
|
||||
const documentsService = services.get(DocumentsService);
|
||||
const response = await documentsService.upsert(req.body);
|
||||
await reply.send(response);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export { documentEndpoints };
|
||||
32
packages/server/src/endpoints/system/system.ts
Normal file
32
packages/server/src/endpoints/system/system.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { DatabaseService } from '#root/services/database/database.ts';
|
||||
|
||||
const systemEndpoints: FastifyPluginAsyncZod = async (instance) => {
|
||||
instance.route({
|
||||
method: 'GET',
|
||||
url: '/ready',
|
||||
schema: {
|
||||
tags: ['system'],
|
||||
operationId: 'GET/system/ready',
|
||||
summary: 'Get system ready state',
|
||||
response: {
|
||||
200: z.object({
|
||||
status: z.literal('ok'),
|
||||
}),
|
||||
},
|
||||
},
|
||||
handler: async (_, reply) => {
|
||||
const { services } = instance;
|
||||
const databaseService = services.get(DatabaseService);
|
||||
const db = await databaseService.getInstance();
|
||||
await db.raw('SELECT 1=1');
|
||||
await reply.send({
|
||||
status: 'ok',
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export { systemEndpoints };
|
||||
Reference in New Issue
Block a user