Skip to content

Instantly share code, notes, and snippets.

import {connect} from 'mongoose'
import {messages} from './messages'
connect(
// Do not commit prod credentials to git tho
'mongodb+srv://NToss:aKmgd43Sf1@cluster0.bkca8.mongodb.net/myFirstDatabase?retryWrites=true&w=majority'
)
.then(() => console.log('Successfully connected to the database'))
.catch(err => console.log('Could not connect to the database. Error...', err))
const mongoose = require("mongoose");
const AppSchema = mongoose.Schema({
message: String,
});
module.exports = mongoose.model("App", AppSchema);
import {Router} from 'express'
import {model, Schema} from 'mongoose'
const Message = model(
'Message',
new Schema({
message: {type: String, required: true},
}),
)
const App = require("../model/app.model.js");
// Create and Save a new Message
exports.create = (req, res) => {
const message = new App({
message: req.body.message,
});
message
.save()
.then((data) => {
module.exports = (app) => {
const App = require("../controllers/app.controller.js");
app.post("/create", App.create);
app.get("/get-all", App.findAll);
app.get("/message/:messageId", App.findOne);
app.put("/message/:messageId", App.update);
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.get("/", (req, res) => {
res.json({message: "Server is running :D"});
});
require("./app/routes/app.routes.js")(app);
const {Pool} = require('pg')
const app = express()
const pool = new Pool({
// confing
})
app.get('/submissions', requiresAuth(), async (req, res) => {
const {rows} = await pool.query(
`
SELECT *
const testQuery = async query => {
const pool = new sql.ConnectionPool({ // ... //})
try {
await pool.connect()
return await pool.request().query(`
BEGIN TRANSACTION
${query}
ROLLBACK TRANSACTION
`)
@aleksejkozin
aleksejkozin / app.js
Created November 13, 2021 18:45
app.js
const {Pool} = require('pg')
const express = require('express')
const {auth, requiresAuth} = require('express-openid-connect')
const app = express()
// Enable OIDC support
// To login into the app use cirnotoss@gmail.com/Lol2021
app.use(
auth({
SELECT *
FROM (
SELECT IT.ID,
ROW_NUMBER()
OVER (
PARTITION BY
IT.VendorId,
IT.ItemNumber,
I.StoreID
ORDER BY I.InvoiceDate DESC, IT.InvoiceID DESC