diff --git a/src/controllers/model.ts b/src/controllers/model.ts index 75cac4b..36967c5 100644 --- a/src/controllers/model.ts +++ b/src/controllers/model.ts @@ -47,17 +47,16 @@ export const getModelByName = async (req: Request, res: Response) => { export const createModel = async (req: Request, res: Response) => { const { name, size, model_type, display_order } = req.body; - let id; switch (model_type) { case 'llm': - id = await LlmService.createLLM(name, size, display_order); + await LlmService.createLLM(name, size, display_order); break; case 'diffusor': - id = await DiffusorService.createDiffusor(name, size, display_order); + await DiffusorService.createDiffusor(name, size, display_order); break; case 'stt': case 'tts': - id = await SpeechModelService.createSpeechModel( + await SpeechModelService.createSpeechModel( name, size, model_type, @@ -69,7 +68,7 @@ export const createModel = async (req: Request, res: Response) => { return; } - res.json({ id }); + res.sendStatus(201); }; export const deleteModel = async (req: Request, res: Response) => { @@ -93,3 +92,29 @@ export const deleteModel = async (req: Request, res: Response) => { } res.sendStatus(204); }; + +export const updateModel = async (req: Request, res: Response) => { + const { name, size, model_type, display_order } = req.body; + switch (model_type) { + case 'llm': + await LlmService.updateLLM(name, size, display_order); + break; + case 'diffusor': + await DiffusorService.updateDiffusor(name, size, display_order); + break; + case 'stt': + case 'tts': + await SpeechModelService.updateSpeechModel( + name, + size, + model_type, + display_order + ); + break; + default: + res.status(400).json({ error: 'Invalid data/payload' }); + return; + } + + res.sendStatus(204); +}; diff --git a/src/routes/models.ts b/src/routes/models.ts index ccd2bb5..e287284 100644 --- a/src/routes/models.ts +++ b/src/routes/models.ts @@ -7,5 +7,6 @@ router.get('/', ModelController.getAllModels); router.post('/', ModelController.createModel); router.get('/:name', ModelController.getModelByName); router.delete('/:name', ModelController.deleteModel); +router.put('/', ModelController.updateModel); export default router; diff --git a/src/services/tables/diffusors.ts b/src/services/tables/diffusors.ts index 194ca53..b4821c0 100644 --- a/src/services/tables/diffusors.ts +++ b/src/services/tables/diffusors.ts @@ -6,11 +6,10 @@ export const createDiffusor = async ( name: string, size: number, display_order: number -): Promise => { +): Promise => { const query = 'INSERT INTO diffusors (name, size, display_order) VALUES (?, ?, ?)'; - const result = await pool.query(query, [name, size, display_order]); - return Number(result.insertId); + await pool.query(query, [name, size, display_order]); }; // Read all Diffusors diff --git a/src/services/tables/llms.ts b/src/services/tables/llms.ts index c7b3394..f56caf3 100644 --- a/src/services/tables/llms.ts +++ b/src/services/tables/llms.ts @@ -6,10 +6,9 @@ export const createLLM = async ( name: string, size: number, display_order: number -): Promise => { +): Promise => { const query = 'INSERT INTO llms (name, size, display_order) VALUES (?, ?, ?)'; - const result = await pool.query(query, [name, size, display_order]); - return Number(result.insertId); + await pool.query(query, [name, size, display_order]); }; // Read all LLMs diff --git a/src/services/tables/speechModels.ts b/src/services/tables/speechModels.ts index fed3519..ed6e477 100644 --- a/src/services/tables/speechModels.ts +++ b/src/services/tables/speechModels.ts @@ -7,16 +7,10 @@ export const createSpeechModel = async ( size: number, model_type: 'tts' | 'stt', display_order: number -): Promise => { +): Promise => { const query = 'INSERT INTO speech_models (name, size, model_type, display_order) VALUES (?, ?, ?, ?)'; - const result = await pool.query(query, [ - name, - size, - model_type, - display_order, - ]); - return Number(result.insertId); + await pool.query(query, [name, size, model_type, display_order]); }; // Read all SpeechModels