Merge branch 'develop' of Software_Engineering_I/greenvironment-server into master

pull/5/head
Trivernis 5 years ago committed by Gitea
commit 3ad3f04859

@ -1,35 +1,43 @@
# Configuration of the database connection
[database]
# A connection uri string to the database
connectionUri = "sqlite://greenvironment.db"
# Configuration for the redis connection
[redis]
# A connection uri string to the redis server
connectionUri = "redis://localhost:6379"
# Configuration of the http server
[server]
# The port the server is running on
port = 8080
# Allow cross origin requests
cors = false
# The timeout for a server response
timeout = 30000
# Configuration for the sessions
[session]
# A secret that is used for the sessions. Must be secure
secret = "REPLACE WITH SAFE RANDOM GENERATED SECRET"
# The maximum age of a cookie. The age is reset with every request of the client
cookieMaxAge = 6048e+5 # 7 days
# Configuration for markdown rendering
[markdown]
# The plugins used in the markdown parser
plugins = ["markdown-it-emoji"]
@ -53,6 +61,7 @@ publicPath = "./public"
# Configuration for the api
[api]
# if graphiql should be enabled
graphiql = true
@ -61,16 +70,22 @@ maxQueryComplexity = 5000
# Configuration for the api rate limit
[api.rateLimit]
# rate limit of /upload
[api.rateLimit.upload]
# The time in milliseconds before the rate limit is reset
expire = 60000
# The total number of calls allowed before rate limiting
total = 10
# rate limit of /graphql
[api.rateLimit.graphql]
# The time in milliseconds before the rate limit is reset
expire = 60000
# The total number of calls allowed before rate limiting
total = 30
total = 60

@ -2,8 +2,8 @@ import * as compression from "compression";
import * as config from "config";
import * as cookieParser from "cookie-parser";
import * as cors from "cors";
import {Request, Response} from "express";
import * as express from "express";
import {Request, Response} from "express";
import * as graphqlHTTP from "express-graphql";
import * as session from "express-session";
import sharedsession = require("express-socket.io-session");
@ -11,12 +11,12 @@ import * as fsx from "fs-extra";
import {buildSchema} from "graphql";
import {importSchema} from "graphql-import";
import queryComplexity, {directiveEstimator, simpleEstimator} from "graphql-query-complexity";
import {IncomingMessage, ServerResponse} from "http";
import * as http from "http";
import {IncomingMessage} from "http";
import * as httpStatus from "http-status";
import * as path from "path";
import {RedisClient} from "redis";
import * as redis from "redis";
import {RedisClient} from "redis";
import {Sequelize} from "sequelize-typescript";
import * as socketIo from "socket.io";
import * as socketIoRedis from "socket.io-redis";
@ -224,7 +224,7 @@ class App {
});
// redirect all request to the angular file
this.app.use((req: any, res: Response) => {
if (config.get("frontend.angularIndex")) {
if (config.has("frontend.angularIndex")) {
const angularIndex = path.join(this.publicPath, config.get("frontend.angularIndex"));
if (fsx.existsSync(path.join(angularIndex))) {
res.sendFile(angularIndex);

@ -254,10 +254,12 @@ export function resolver(req: any, res: any): any {
},
async deletePost({postId}: { postId: number }) {
if (postId) {
const post = await models.Post.findByPk(postId, {include: [{
const post = await models.Post.findByPk(postId, {
include: [{
as: "rAuthor",
model: models.User,
}]});
}],
});
const isAdmin = (await models.User.findOne({where: {id: req.session.userId}})).isAdmin;
if (post.rAuthor.id === req.session.userId || isAdmin) {
try {

@ -2,6 +2,7 @@ process.env.NODE_CONFIG_DIR = __dirname + "/../config";
// tslint:disable:no-console
import * as cluster from "cluster";
import App from "./app";
const numCPUs = require("os").cpus().length;
if (cluster.isMaster) {

@ -14,8 +14,8 @@ import {NoActionSpecifiedError} from "./errors/NoActionSpecifiedError";
import {UserNotFoundError} from "./errors/UserNotFoundError";
import globals from "./globals";
import {InternalEvents} from "./InternalEvents";
import {Activity} from "./models";
import * as models from "./models";
import {Activity} from "./models";
// tslint:disable:completed-docs
@ -263,8 +263,10 @@ namespace dataaccess {
export async function createRequest(sender: number, receiver: number, requestType?: RequestType) {
requestType = requestType || RequestType.FRIENDREQUEST;
const requestExists = !!await models.Request.findOne({where:
{senderId: sender, receiverId: receiver, requestType}});
const requestExists = !!await models.Request.findOne({
where:
{senderId: sender, receiverId: receiver, requestType},
});
if (!requestExists) {
const request = await models.Request.create({senderId: sender, receiverId: receiver, requestType});

@ -40,7 +40,7 @@ export class ChatRoom extends Model<ChatRoom> {
public async messages({first, offset}: { first: number, offset: number }): Promise<ChatMessage[]> {
const limit = first ?? 10;
offset = offset ?? 0;
return await this.$get("rMessages", {limit, offset}) as ChatMessage[];
return await this.$get("rMessages", {limit, offset, order: [["id", "DESC"]]}) as ChatMessage[];
}
/**

Loading…
Cancel
Save