Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client } = require('pg');
- const client = new Client({
- user: 'postgres',
- host: 'localhost',
- database: 'mydb',
- password: 'changeme',
- port: 5432,
- SSL: false
- });
- client.connect();
- function SaveStatus(A, B, Status, Type) {
- try {
- if (A && B) {
- var query = '';
- var values = [];//[A, B, Status];
- if (Type === 'S') {
- query = 'INSERT INTO public.TableX(A, B, StatusCode)VALUES($1, $2, $3)';
- values = [A, B, Status];
- if (Status > 1) {
- query = 'UPDATE public.TableX SET StatusCode = $3 WHERE B = $2';
- }
- }
- if (Type === 'Status') {
- query = 'INSERT INTO public.TableY(A, B, StatusCode)VALUES($1, $2, $3)';
- values = [A, B, Status];
- if (Status > 1) {
- query = 'UPDATE public.TableY SET StatusCode = $3 WHERE B = $2';
- }
- }
- client.query(query, values)
- .then(function (data) {
- res.status(200)
- .json({
- status: 'success',
- data: data,
- message: 'Ok'
- });
- })
- .catch(function (err) {
- return next(err);
- });
- }
- else {
- res.status(200)
- .json({
- status: 'failed',
- data: null,
- message: 'failed to update text verification status'
- });
- }
- }
- catch (err) {
- next(err);
- }
- }
- function InsertStatusX(A, B) {
- Status = 1;
- }
- function UpdateStatusX(A, B, Status) {
- }
- function InsertStatusY(A, B) {
- Status = 1;
- }
- function UpdateStatusY(A, B, Status) {
- }
Add Comment
Please, Sign In to add comment