Guest User

Untitled

a guest
Dec 1st, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. const { Client } = require('pg');
  2. const client = new Client({
  3. user: 'postgres',
  4. host: 'localhost',
  5. database: 'mydb',
  6. password: 'changeme',
  7. port: 5432,
  8. SSL: false
  9. });
  10. client.connect();
  11.  
  12. function SaveStatus(A, B, Status, Type) {
  13. try {
  14. if (A && B) {
  15. var query = '';
  16. var values = [];//[A, B, Status];
  17. if (Type === 'S') {
  18. query = 'INSERT INTO public.TableX(A, B, StatusCode)VALUES($1, $2, $3)';
  19. values = [A, B, Status];
  20. if (Status > 1) {
  21. query = 'UPDATE public.TableX SET StatusCode = $3 WHERE B = $2';
  22. }
  23. }
  24. if (Type === 'Status') {
  25. query = 'INSERT INTO public.TableY(A, B, StatusCode)VALUES($1, $2, $3)';
  26. values = [A, B, Status];
  27. if (Status > 1) {
  28. query = 'UPDATE public.TableY SET StatusCode = $3 WHERE B = $2';
  29. }
  30. }
  31.  
  32. client.query(query, values)
  33. .then(function (data) {
  34. res.status(200)
  35. .json({
  36. status: 'success',
  37. data: data,
  38. message: 'Ok'
  39. });
  40. })
  41. .catch(function (err) {
  42. return next(err);
  43. });
  44. }
  45. else {
  46. res.status(200)
  47. .json({
  48. status: 'failed',
  49. data: null,
  50. message: 'failed to update text verification status'
  51. });
  52. }
  53. }
  54. catch (err) {
  55. next(err);
  56. }
  57. }
  58.  
  59. function InsertStatusX(A, B) {
  60. Status = 1;
  61. }
  62.  
  63. function UpdateStatusX(A, B, Status) {
  64. }
  65.  
  66. function InsertStatusY(A, B) {
  67. Status = 1;
  68. }
  69.  
  70. function UpdateStatusY(A, B, Status) {
  71. }
Add Comment
Please, Sign In to add comment