Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Twoguini committed Nov 1, 2023
1 parent ba287c3 commit 1783959
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 59 deletions.
5 changes: 3 additions & 2 deletions src/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const initOptions = {
}
}

const pgp = require('pg-promise')(initOptions);
import pg_promisses from 'pg-promise';
const pgp = pg_promisses (initOptions);

const databaseConnetion = pgp("postgresql://postgres:1211@localhost:5432/users");
const databaseConnetion = pgp("postgresql://postgres:12341234@localhost:5432/users");

export default databaseConnetion;
12 changes: 12 additions & 0 deletions src/db/scheme.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DROP DATABASE IF EXISTS users;

CREATE DATABASE users;

CREATE TABLE students (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(60) NOT NULL,
password VARCHAR(18) NOT NULL,
is_admin BIT DEFAULT 0,
data_Criação DATE DEFAULT GETDATE(),
pontuation int(5) NOT NULL
);
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import _ from 'lodash';
import path from 'path';
import handlebars from 'express-handlebars';
import bodyParser from 'body-parser';
import {WebQuest as WebQuestRouter} from './routes/WebQuest.js';
import webQuest from './routes/WebQuest.js';
import session from 'express-session';
import flash from 'connect-flash';
import databaseConnetion from './db/db.js';
import userPages from './routes/User.js';

import { fileURLToPath } from 'url';

const app = xpress();

// SECTION: ========================= Directories =========================
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const publicPath = path.join(__dirname, 'public'); // NOTE: Public Dir
// !SECTION ===============================================================

Expand Down Expand Up @@ -46,7 +48,7 @@ app.set('view engine', 'handlebars'); // NOTE: ...
// !SECTION ===============================================================

// SECTION: ============================ Routes ===========================
app.use('/', WebQuestRouter);
app.use('/', webQuest);
app.use('/', userPages);
// !SECTION ===============================================================

Expand Down
158 changes: 118 additions & 40 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions src/queries/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import databaseConnection from '../db/db';
import databaseConnection from '../db/db.js';

export default async function getUsers(req, res, next){
export default async function getUsers(req, res, next){
try{
let users = await databaseConnection.any("SELECT * FROM students");
res.status(200).json({
Expand All @@ -11,11 +11,3 @@ export default async function getUsers(req, res, next){
next(err);
}
}

export function guilhermeSeuMerdaViraHomemEParaDeUsarEssaPorraDeArrowFunctionQueEraPraSerUmaPiadaEVirouIssoAi() {

}

const arrow = () => {

}
8 changes: 4 additions & 4 deletions src/routes/WebQuest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Express } from 'express';
const webQuest = Express.Router();
import { users } from '../queries/users.js';
import express from 'express';
import users from '../queries/users.js';
const webQuest = express.Router();

webQuest.get('/home', (req, res) =>{
// NOTE: Home Page
Expand All @@ -17,6 +17,6 @@ webQuest.get('/questions', (req, res) =>{
res.render('webQuest/quests');
});

webQuest.get('/users', users.getUsers);
webQuest.get('/users', users);

export default webQuest;

0 comments on commit 1783959

Please sign in to comment.