Removed frontend part and added graphql implementation

pull/1/head
Trivernis 5 years ago
parent 1d97e3305e
commit 84b683db11

@ -3,7 +3,7 @@ const sass = require('gulp-sass');
const ts = require('gulp-typescript'); const ts = require('gulp-typescript');
const minify = require('gulp-minify'); const minify = require('gulp-minify');
const del = require('delete'); const del = require('delete');
const gulp = require('gulp');
function clearDist(cb) { function clearDist(cb) {
del('dist/*', cb); del('dist/*', cb);

6
package-lock.json generated

@ -3348,6 +3348,12 @@
} }
} }
}, },
"gulp-angular": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/gulp-angular/-/gulp-angular-0.1.2.tgz",
"integrity": "sha1-ljV2ul7qoDZqMf6l7S7AHvC0O3g=",
"dev": true
},
"gulp-minify": { "gulp-minify": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/gulp-minify/-/gulp-minify-3.1.0.tgz", "resolved": "https://registry.npmjs.org/gulp-minify/-/gulp-minify-3.1.0.tgz",

@ -35,6 +35,7 @@
"@types/winston": "^2.4.4", "@types/winston": "^2.4.4",
"delete": "^1.1.0", "delete": "^1.1.0",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-angular": "^0.1.2",
"gulp-minify": "^3.1.0", "gulp-minify": "^3.1.0",
"gulp-sass": "^4.0.2", "gulp-sass": "^4.0.2",
"gulp-typescript": "^5.0.1", "gulp-typescript": "^5.0.1",

@ -95,7 +95,7 @@ namespace dataaccess {
* @param authorId * @param authorId
* @param type * @param type
*/ */
export async function createPost(content: string, authorId: number, type: string) { export async function createPost(content: string, authorId: number, type?: string) {
const result = await queryHelper.first({ const result = await queryHelper.first({
text: "INSERT INTO posts (content, author, type) VALUES ($1, $2, $3) RETURNING *", text: "INSERT INTO posts (content, author, type) VALUES ($1, $2, $3) RETURNING *",
values: [content, authorId, type], values: [content, authorId, type],
@ -103,6 +103,18 @@ namespace dataaccess {
return new Post(result.id, result); return new Post(result.id, result);
} }
/**
* Deletes a post
* @param postId
*/
export async function deletePost(postId: number) {
const result = await queryHelper.first({
text: "DELETE FROM posts WHERE posts.id = $1",
values: [postId],
});
return true;
}
/** /**
* Enum representing the types of votes that can be performed on a post. * Enum representing the types of votes that can be performed on a post.
*/ */

@ -91,11 +91,9 @@ type User {
"represents a single user post" "represents a single user post"
type Post { type Post {
"returns the path to the posts picture if it has one"
picture: String
"returns the text of the post" "returns the text of the post"
text: String content: String
"upvotes of the Post" "upvotes of the Post"
upvotes: Int! upvotes: Int!
@ -111,9 +109,6 @@ type Post {
"returns the type of vote the user performed on the post" "returns the type of vote the user performed on the post"
userVote: VoteType userVote: VoteType
"returns the tags of the post"
tags: [String]
} }
"represents a request of any type" "represents a request of any type"

@ -1,7 +1,6 @@
import {Router} from "express"; import {Router} from "express";
import {GraphQLError} from "graphql"; import {GraphQLError} from "graphql";
import * as status from "http-status"; import * as status from "http-status";
import {constants} from "http2";
import {Server} from "socket.io"; import {Server} from "socket.io";
import dataaccess from "../lib/dataaccess"; import dataaccess from "../lib/dataaccess";
import {Post} from "../lib/dataaccess/Post"; import {Post} from "../lib/dataaccess/Post";
@ -18,7 +17,6 @@ class HomeRoute extends Route {
constructor() { constructor() {
super(); super();
this.router = Router(); this.router = Router();
this.configure();
} }
/** /**
@ -56,7 +54,7 @@ class HomeRoute extends Route {
req.session.cookiesAccepted = true; req.session.cookiesAccepted = true;
return true; return true;
}, },
async login(args: any) { async login(args: {email: string, passwordHash: string}) {
if (args.email && args.passwordHash) { if (args.email && args.passwordHash) {
const user = await dataaccess.getUserByLogin(args.email, args.passwordHash); const user = await dataaccess.getUserByLogin(args.email, args.passwordHash);
if (user && user.id) { if (user && user.id) {
@ -80,7 +78,7 @@ class HomeRoute extends Route {
return new GraphQLError("User is not logged in."); return new GraphQLError("User is not logged in.");
} }
}, },
async register(args: any) { async register(args: {username: string, email: string, passwordHash: string}) {
if (args.username && args.email && args.passwordHash) { if (args.username && args.email && args.passwordHash) {
const user = await dataaccess.registerUser(args.username, args.email, args.passwordHash); const user = await dataaccess.registerUser(args.username, args.email, args.passwordHash);
if (user) { if (user) {
@ -95,7 +93,7 @@ class HomeRoute extends Route {
return new GraphQLError("No username, email or password given."); return new GraphQLError("No username, email or password given.");
} }
}, },
async vote(args: any) { async vote(args: {postId: number, type: dataaccess.VoteType}) {
if (args.postId && args.type) { if (args.postId && args.type) {
if (req.session.userId) { if (req.session.userId) {
return await (new Post(args.postId)).vote(req.session.userId, args.type); return await (new Post(args.postId)).vote(req.session.userId, args.type);
@ -108,22 +106,33 @@ class HomeRoute extends Route {
return new GraphQLError("No postId or type given."); return new GraphQLError("No postId or type given.");
} }
}, },
}; async createPost(args: {content: string}) {
if (args.content) {
if (req.session.userId) {
return await dataaccess.createPost(args.content, req.session.userId);
} else {
res.status(status.UNAUTHORIZED);
return new GraphQLError("Not logged in.");
} }
} else {
/** res.status(status.BAD_REQUEST);
* Configures the route. return new GraphQLError("Can't create empty post.");
*/ }
private configure() { },
this.router.get("/", (req, res) => { async deletePost(args: {postId: number}) {
res.render("home"); if (args.postId) {
}); const post = new Post(args.postId);
this.router.get("/login", (req, res) => { if ((await post.author()).id === req.session.userId) {
res.render("login"); return await dataaccess.deletePost(post.id);
}); } else {
this.router.get("/register", (req, res) => { res.status(status.FORBIDDEN);
res.render("register"); return new GraphQLError("User is not author of the post.");
}); }
} else {
return new GraphQLError("No postId given.");
}
},
};
} }
} }

@ -1,13 +0,0 @@
div#feedcontainer
div.postinput
input(type=text placeholder='Post something')
button.submitbutton Submit
div.feeditem
div.itemhead
span.title Testuser
span.handle
a(href='#') @testuser
span.date 23.09.19 10:07
p.text
| Example Test text.
| This is a test

@ -1 +0,0 @@
div#friendscontainer

@ -1,9 +0,0 @@
html
head
title Greenvironment Network
include ../includes/head
body
div#content
include ../includes/stylebar
include feed
include friends

@ -1 +0,0 @@
link(rel='stylesheet' href='stylesheets/style.css')

@ -1,2 +0,0 @@
div.stylebar
h1 Greenvironment

@ -1,8 +0,0 @@
html
head
title Greenvironment Network Login
include ../includes/head
body
div#content
include ../includes/stylebar
include login

@ -1,6 +0,0 @@
div#input-login
input(type=text placeholder='username')
input(type=text placeholder='password')
button.loginButton Login
a(href="/register" )
| You aren´t part of greenvironment yet? - create a new account

@ -1,8 +0,0 @@
html
head
title Greenvironment Network Register
include ../includes/head
body
div#content
include ../includes/stylebar
include register

@ -1,8 +0,0 @@
div#input-register
input(type=text placeholder='username')
input(type=text placeholder='email')
input(type=text placeholder='password')
input(type=text placeholder='repeat password')
button.registerButton Register
a(href="/login" )
| You are already part of greenvironment? - login
Loading…
Cancel
Save