-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comandos: /gpt - para receber a resposta em texto /gptM - pra receber a resposta em imagem
- Loading branch information
Showing
17 changed files
with
468 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Request, Response } from "express"; | ||
|
||
import { getIO } from "../libs/socket"; | ||
import AppError from "../errors/AppError"; | ||
|
||
import UpdateIntegrationService from "../services/IntegrationServices/UpdateIntegrationService"; | ||
import ListIntegrationsService from "../services/IntegrationServices/ListIntegrationsService"; | ||
|
||
export const index = async (req: Request, res: Response): Promise<Response> => { | ||
if (req.user.profile === "") { | ||
throw new AppError("ERR_NO_PERMISSION", 403); | ||
} | ||
|
||
const integrations = await ListIntegrationsService(); | ||
|
||
return res.status(200).json(integrations); | ||
}; | ||
|
||
export const update = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<Response> => { | ||
if (req.user.profile !== "admin") { | ||
throw new AppError("ERR_NO_PERMISSION", 403); | ||
} | ||
const { integrationKey: key } = req.params; | ||
const { value } = req.body; | ||
|
||
const integration = await UpdateIntegrationService({ | ||
key, | ||
value | ||
}); | ||
|
||
const io = getIO(); | ||
io.emit("integrations", { | ||
action: "update", | ||
integration | ||
}); | ||
|
||
return res.status(200).json(integration); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
backend/src/database/migrations/20230503231400-create-integrations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { QueryInterface, DataTypes } from "sequelize"; | ||
|
||
module.exports = { | ||
up: (queryInterface: QueryInterface) => { | ||
return queryInterface.createTable("Integrations", { | ||
key: { | ||
type: DataTypes.STRING, | ||
primaryKey: true, | ||
allowNull: false | ||
}, | ||
value: { | ||
type: DataTypes.TEXT, | ||
allowNull: false | ||
}, | ||
createdAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false | ||
}, | ||
updatedAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false | ||
} | ||
}); | ||
}, | ||
|
||
down: (queryInterface: QueryInterface) => { | ||
return queryInterface.dropTable("Integrations"); | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
backend/src/database/seeds/20230501010700-create-openai-settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { QueryInterface } from "sequelize"; | ||
|
||
module.exports = { | ||
up: (queryInterface: QueryInterface) => { | ||
return queryInterface.bulkInsert( | ||
"Integrations", | ||
[ | ||
{ | ||
key: "organization", | ||
value: "", | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, | ||
{ | ||
key: "apikey", | ||
value: "", | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
} | ||
], | ||
{} | ||
); | ||
}, | ||
|
||
down: (queryInterface: QueryInterface) => { | ||
return queryInterface.bulkDelete("Integrations", {}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
Table, | ||
Column, | ||
CreatedAt, | ||
UpdatedAt, | ||
Model, | ||
PrimaryKey | ||
} from "sequelize-typescript"; | ||
|
||
@Table | ||
class Integration extends Model<Integration> { | ||
@PrimaryKey | ||
@Column | ||
key: string; | ||
|
||
@Column | ||
value: string; | ||
|
||
@CreatedAt | ||
createdAt: Date; | ||
|
||
@UpdatedAt | ||
updatedAt: Date; | ||
} | ||
|
||
export default Integration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Router } from "express"; | ||
import isAuth from "../middleware/isAuth"; | ||
|
||
import * as IntegrationController from "../controllers/IntegrationController"; | ||
|
||
const integrationRoutes = Router(); | ||
|
||
integrationRoutes.get("/integrations", isAuth, IntegrationController.index); | ||
|
||
integrationRoutes.put( | ||
"/integrations/:integrationKey", | ||
isAuth, | ||
IntegrationController.update | ||
); | ||
|
||
export default integrationRoutes; |
11 changes: 11 additions & 0 deletions
11
backend/src/services/IntegrationServices/ListIntegrationsService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Integration from "../../models/Integration"; | ||
|
||
const ListIntegrationsService = async (): Promise< | ||
Integration[] | undefined | ||
> => { | ||
const integrations = await Integration.findAll(); | ||
|
||
return integrations; | ||
}; | ||
|
||
export default ListIntegrationsService; |
26 changes: 26 additions & 0 deletions
26
backend/src/services/IntegrationServices/UpdateIntegrationService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import AppError from "../../errors/AppError"; | ||
import Integration from "../../models/Integration"; | ||
|
||
interface Request { | ||
key: string; | ||
value: string; | ||
} | ||
|
||
const UpdateIntegrationService = async ({ | ||
key, | ||
value | ||
}: Request): Promise<Integration | undefined> => { | ||
const integration = await Integration.findOne({ | ||
where: { key } | ||
}); | ||
|
||
if (!integration) { | ||
throw new AppError("ERR_NO_INTEGRATION_FOUND", 404); | ||
} | ||
|
||
await integration.update({ value }); | ||
|
||
return integration; | ||
}; | ||
|
||
export default UpdateIntegrationService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.