-
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.
Implementando gerador de CodeSnippet
- Loading branch information
Showing
8 changed files
with
368 additions
and
16 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
33 changes: 33 additions & 0 deletions
33
backend/src/database/migrations/20240921112934-alter-userId-foreign-key-on-tickets.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,33 @@ | ||
import { QueryInterface } from "sequelize"; | ||
|
||
module.exports = { | ||
up: async (queryInterface: QueryInterface) => { | ||
await queryInterface.removeConstraint("tickets", "tickets_ibfk_2"); | ||
|
||
await queryInterface.addConstraint("tickets", ["userId"], { | ||
type: "foreign key", | ||
name: "tickets_ibfk_2", | ||
references: { | ||
table: "users", | ||
field: "id" | ||
}, | ||
onDelete: "CASCADE", | ||
onUpdate: "CASCADE" | ||
}); | ||
}, | ||
|
||
down: async (queryInterface: QueryInterface) => { | ||
await queryInterface.removeConstraint("tickets", "tickets_ibfk_2"); | ||
|
||
await queryInterface.addConstraint("tickets", ["userId"], { | ||
type: "foreign key", | ||
name: "tickets_ibfk_2", | ||
references: { | ||
table: "users", | ||
field: "id" | ||
}, | ||
onDelete: "SET NULL", | ||
onUpdate: "CASCADE" | ||
}); | ||
} | ||
}; |
43 changes: 43 additions & 0 deletions
43
backend/src/database/migrations/20240921153422-alter-queueId-foreign-key-on-tickets.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,43 @@ | ||
import { QueryInterface } from "sequelize"; | ||
|
||
export default { | ||
up: async (queryInterface: QueryInterface) => { | ||
// Remover a constraint antiga | ||
await queryInterface.removeConstraint( | ||
"tickets", | ||
"Tickets_queueId_foreign_idx" | ||
); | ||
|
||
// Adicionar a nova constraint com SET NULL e CASCADE | ||
await queryInterface.addConstraint("tickets", ["queueId"], { | ||
type: "foreign key", | ||
name: "Tickets_queueId_foreign_idx", | ||
references: { | ||
table: "queues", | ||
field: "id" | ||
}, | ||
onDelete: "SET NULL", // Ao deletar, coloca NULL no campo queueId | ||
onUpdate: "CASCADE" // Ao atualizar o id na tabela queues, atualiza o queueId em tickets | ||
}); | ||
}, | ||
|
||
down: async (queryInterface: QueryInterface) => { | ||
// Remover a constraint recém adicionada | ||
await queryInterface.removeConstraint( | ||
"tickets", | ||
"Tickets_queueId_foreign_idx" | ||
); | ||
|
||
// Restaurar a constraint antiga | ||
await queryInterface.addConstraint("tickets", ["queueId"], { | ||
type: "foreign key", | ||
name: "Tickets_queueId_foreign_idx", | ||
references: { | ||
table: "queues", | ||
field: "id" | ||
}, | ||
onDelete: "RESTRICT", | ||
onUpdate: "CASCADE" | ||
}); | ||
} | ||
}; |
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
118 changes: 118 additions & 0 deletions
118
frontend/src/components/CodeSnippetGenerator/codeSnippets.js
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,118 @@ | ||
const codeSnippets = { | ||
HTTP: (number, body, userId, queueId, whatsappId, token) => `POST ${process.env.REACT_APP_BACKEND_URL}/api/messages/send HTTP/1.1 | ||
User-Agent: vscode-restclient | ||
Authorization: Bearer ${token} | ||
Content-Type: application/json | ||
Host: localhost:4000 | ||
Content-Length: ${85 + body.length} | ||
{ | ||
"number": "${number}", | ||
"body": "${body}", | ||
"userId": "${userId}", | ||
"queueId": "${queueId}", | ||
"whatsappId": "${whatsappId}" | ||
}`, | ||
JavaScript_JQuery: (number, body, userId, queueId, whatsappId, token) => `const settings = { | ||
"async": true, | ||
"crossDomain": true, | ||
"url": "${process.env.REACT_APP_BACKEND_URL}/api/messages/send}", | ||
"method": "POST", | ||
"headers": { | ||
"user-agent": "vscode-restclient", | ||
"authorization": "Bearer ${token}", | ||
"content-type": "application/json" | ||
}, | ||
"processData": false, | ||
"data": "{\"number\": \"${number}\",\"body\": \"${body}\",\"userId\": \"${userId}\",\"queueId\": \"${queueId}\",\"whatsappId\": \"${whatsappId}\"}" | ||
}; | ||
$.ajax(settings).done(function (response) { | ||
console.log(response); | ||
}); | ||
`, | ||
JavaScript_fetch: (number, body, userId, queueId, whatsappId, token) => ` | ||
fetch("${process.env.REACT_APP_BACKEND_URL}/api/messages/send", { | ||
"method": "POST", | ||
"headers": { | ||
"user-agent": "vscode-restclient", | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer ${token}", | ||
}, | ||
"body": { | ||
number: "${number}", | ||
body: '${body}', | ||
userId: '${userId}', | ||
queueId: '${queueId}', | ||
whatsAppId: '${whatsappId}' | ||
}, | ||
}) | ||
.then(response => { | ||
console.log(response); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
`, | ||
NODEjs_Request: (number, body, userId, queueId, whatsappId, token) => ` | ||
const request = require('request'); | ||
const options = { | ||
method: 'POST', | ||
url: '${process.env.REACT_APP_BACKEND_URL}/api/messages/send', | ||
headers: { | ||
'user-agent': 'vscode-restclient', | ||
'Authorization': 'Bearer ${token}', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: { | ||
number: '${number}', | ||
body: '${body}', | ||
userId: '${userId}', | ||
queueId: '${queueId}', | ||
whatsAppId: '${whatsappId}', | ||
}, | ||
json: true | ||
}; | ||
request(options, function (error, response, body) { | ||
if (error) throw new Error(error); | ||
console.log('Response:', body); | ||
});`, | ||
PHP_cURL: (number, body, userId, queueId, whatsappId, token) => ` | ||
<?php | ||
$curl = curl_init(); | ||
curl_setopt_array($curl, [ | ||
CURLOPT_PORT => "4000", | ||
CURLOPT_URL => "${process.env.REACT_APP_BACKEND_URL}/api/messages/send", | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 30, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => "POST", | ||
CURLOPT_POSTFIELDS => "{\"number\": \"${number}\",\"body\": \"${body}\",\"userId\": \"${userId}\",\"queueId\": \"${queueId}\",\"whatsappId\": \"${whatsappId}\"}", | ||
CURLOPT_HTTPHEADER => [ | ||
'Authorization': 'Bearer ${token}', | ||
"content-type: application/json", | ||
"user-agent: vscode-restclient" | ||
], | ||
]); | ||
$response = curl_exec($curl); | ||
$err = curl_error($curl); | ||
curl_close($curl); | ||
if ($err) { | ||
echo "cURL Error #:" . $err; | ||
} else { | ||
echo $response; | ||
} | ||
`, | ||
}; | ||
|
||
export default codeSnippets; |
Oops, something went wrong.