Flowise

Форк
0
87 строк · 2.9 Кб
1
import { Request, Response, NextFunction } from 'express'
2
import credentialsService from '../../services/credentials'
3
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
4
import { StatusCodes } from 'http-status-codes'
5

6
const createCredential = async (req: Request, res: Response, next: NextFunction) => {
7
    try {
8
        if (!req.body) {
9
            throw new InternalFlowiseError(
10
                StatusCodes.PRECONDITION_FAILED,
11
                `Error: credentialsController.createCredential - body not provided!`
12
            )
13
        }
14
        const apiResponse = await credentialsService.createCredential(req.body)
15
        return res.json(apiResponse)
16
    } catch (error) {
17
        next(error)
18
    }
19
}
20

21
const deleteCredentials = async (req: Request, res: Response, next: NextFunction) => {
22
    try {
23
        if (typeof req.params === 'undefined' || !req.params.id) {
24
            throw new InternalFlowiseError(
25
                StatusCodes.PRECONDITION_FAILED,
26
                `Error: credentialsController.deleteCredentials - id not provided!`
27
            )
28
        }
29
        const apiResponse = await credentialsService.deleteCredentials(req.params.id)
30
        return res.json(apiResponse)
31
    } catch (error) {
32
        next(error)
33
    }
34
}
35

36
const getAllCredentials = async (req: Request, res: Response, next: NextFunction) => {
37
    try {
38
        const apiResponse = await credentialsService.getAllCredentials(req.query.credentialName)
39
        return res.json(apiResponse)
40
    } catch (error) {
41
        next(error)
42
    }
43
}
44

45
const getCredentialById = async (req: Request, res: Response, next: NextFunction) => {
46
    try {
47
        if (typeof req.params === 'undefined' || !req.params.id) {
48
            throw new InternalFlowiseError(
49
                StatusCodes.PRECONDITION_FAILED,
50
                `Error: credentialsController.getCredentialById - id not provided!`
51
            )
52
        }
53
        const apiResponse = await credentialsService.getCredentialById(req.params.id)
54
        return res.json(apiResponse)
55
    } catch (error) {
56
        next(error)
57
    }
58
}
59

60
const updateCredential = async (req: Request, res: Response, next: NextFunction) => {
61
    try {
62
        if (typeof req.params === 'undefined' || !req.params.id) {
63
            throw new InternalFlowiseError(
64
                StatusCodes.PRECONDITION_FAILED,
65
                `Error: credentialsController.updateCredential - id not provided!`
66
            )
67
        }
68
        if (!req.body) {
69
            throw new InternalFlowiseError(
70
                StatusCodes.PRECONDITION_FAILED,
71
                `Error: credentialsController.updateCredential - body not provided!`
72
            )
73
        }
74
        const apiResponse = await credentialsService.updateCredential(req.params.id, req.body)
75
        return res.json(apiResponse)
76
    } catch (error) {
77
        next(error)
78
    }
79
}
80

81
export default {
82
    createCredential,
83
    deleteCredentials,
84
    getAllCredentials,
85
    getCredentialById,
86
    updateCredential
87
}
88

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.