Fix Style Issues

pull/4/head
Trivernis 5 years ago
parent 5440cca701
commit 8f3b50a4ce

@ -6,6 +6,7 @@ import * as express from "express";
import {Request, Response} from "express"; import {Request, Response} from "express";
import * as graphqlHTTP from "express-graphql"; import * as graphqlHTTP from "express-graphql";
import * as session from "express-session"; import * as session from "express-session";
import sharedsession = require("express-socket.io-session");
import * as fsx from "fs-extra"; import * as fsx from "fs-extra";
import {buildSchema} from "graphql"; import {buildSchema} from "graphql";
import {importSchema} from "graphql-import"; import {importSchema} from "graphql-import";
@ -24,7 +25,6 @@ import dataaccess from "./lib/dataAccess";
import globals from "./lib/globals"; import globals from "./lib/globals";
import HomeRoute from "./routes/HomeRoute"; import HomeRoute from "./routes/HomeRoute";
import {UploadRoute} from "./routes/UploadRoute"; import {UploadRoute} from "./routes/UploadRoute";
import sharedsession = require("express-socket.io-session");
const SequelizeStore = require("connect-session-sequelize")(session.Store); const SequelizeStore = require("connect-session-sequelize")(session.Store);
const createLimiter: (...args: any) => any = require("express-limiter"); const createLimiter: (...args: any) => any = require("express-limiter");

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

@ -61,7 +61,7 @@ type Mutation {
"Report the post" "Report the post"
report(postId: ID!): Boolean! report(postId: ID!): Boolean!
"send a request" "send a request"
sendRequest(receiver: ID!, type: RequestType): Request sendRequest(receiver: ID!, type: RequestType): Request
"lets you accept a request for a given request id" "lets you accept a request for a given request id"

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

@ -14,8 +14,8 @@ import {NoActionSpecifiedError} from "./errors/NoActionSpecifiedError";
import {UserNotFoundError} from "./errors/UserNotFoundError"; import {UserNotFoundError} from "./errors/UserNotFoundError";
import globals from "./globals"; import globals from "./globals";
import {InternalEvents} from "./InternalEvents"; import {InternalEvents} from "./InternalEvents";
import {Activity} from "./models";
import * as models from "./models"; import * as models from "./models";
import {Activity} from "./models";
// tslint:disable:completed-docs // tslint:disable:completed-docs
@ -160,7 +160,7 @@ namespace dataaccess {
} else { } else {
// more performant way to get the votes with plain sql // more performant way to get the votes with plain sql
return await sequelize.query( return await sequelize.query(
`SELECT * FROM ( `SELECT * FROM (
SELECT *, SELECT *,
(SELECT count(*) FROM post_votes WHERE vote_type = 'UPVOTE' AND post_id = posts.id) AS upvotes , (SELECT count(*) FROM post_votes WHERE vote_type = 'UPVOTE' AND post_id = posts.id) AS upvotes ,
(SELECT count(*) FROM post_votes WHERE vote_type = 'DOWNVOTE' AND post_id = posts.id) AS downvotes (SELECT count(*) FROM post_votes WHERE vote_type = 'DOWNVOTE' AND post_id = posts.id) AS downvotes
@ -195,7 +195,7 @@ namespace dataaccess {
* Deletes a post * Deletes a post
* @param postId * @param postId
*/ */
export async function deletePost(postId: number): Promise<boolean|GraphQLError> { export async function deletePost(postId: number): Promise<boolean | GraphQLError> {
try { try {
const post = await models.Post.findByPk(postId, {include: [{model: Activity}, {association: "rAuthor"}]}); const post = await models.Post.findByPk(postId, {include: [{model: Activity}, {association: "rAuthor"}]});
const activity = await post.activity(); const activity = await post.activity();
@ -263,8 +263,10 @@ namespace dataaccess {
export async function createRequest(sender: number, receiver: number, requestType?: RequestType) { export async function createRequest(sender: number, receiver: number, requestType?: RequestType) {
requestType = requestType || RequestType.FRIENDREQUEST; requestType = requestType || RequestType.FRIENDREQUEST;
const requestExists = !!await models.Request.findOne({where: const requestExists = !!await models.Request.findOne({
{senderId: sender, receiverId: receiver, requestType}}); where:
{senderId: sender, receiverId: receiver, requestType},
});
if (!requestExists) { if (!requestExists) {
const request = await models.Request.create({senderId: sender, receiverId: receiver, requestType}); const request = await models.Request.create({senderId: sender, receiverId: receiver, requestType});

@ -4,7 +4,7 @@ import {BaseError} from "./BaseError";
* An error that is thrown when a specified user was not found * An error that is thrown when a specified user was not found
*/ */
export class UserNotFoundError extends BaseError { export class UserNotFoundError extends BaseError {
constructor(username: (string|number)) { constructor(username: (string | number)) {
super(`User ${username} not found!`); super(`User ${username} not found!`);
} }
} }

@ -37,7 +37,7 @@ export class ChatRoom extends Model<ChatRoom> {
/** /**
* Returns the messages that have been sent in the chatroom * Returns the messages that have been sent in the chatroom
*/ */
public async messages({first, offset}: {first: number, offset: number}): Promise<ChatMessage[]> { public async messages({first, offset}: { first: number, offset: number }): Promise<ChatMessage[]> {
const limit = first ?? 10; const limit = first ?? 10;
offset = offset ?? 0; offset = offset ?? 0;
return await this.$get("rMessages", {limit, offset}) as ChatMessage[]; return await this.$get("rMessages", {limit, offset}) as ChatMessage[];

@ -55,7 +55,7 @@ export class Event extends Model<Event> {
* @param first * @param first
* @param offset * @param offset
*/ */
public async participants({first, offset}: {first: number, offset: number}): Promise<User[]> { public async participants({first, offset}: { first: number, offset: number }): Promise<User[]> {
const limit = first ?? 10; const limit = first ?? 10;
offset = offset ?? 0; offset = offset ?? 0;
return await this.$get("rParticipants", {limit, offset}) as User[]; return await this.$get("rParticipants", {limit, offset}) as User[];
@ -66,7 +66,7 @@ export class Event extends Model<Event> {
* @param userId * @param userId
* @param request * @param request
*/ */
public async joined({userId}: {userId: number}, request: any): Promise<boolean> { public async joined({userId}: { userId: number }, request: any): Promise<boolean> {
userId = userId ?? request.session.userId; userId = userId ?? request.session.userId;
if (userId) { if (userId) {
const participants = await this.$get("rParticipants", {where: {id: userId}}) as User[]; const participants = await this.$get("rParticipants", {where: {id: userId}}) as User[];

@ -127,7 +127,7 @@ export class Group extends Model<Group> {
* @param userId * @param userId
* @param request * @param request
*/ */
public async joined({userId}: {userId: number}, request: any): Promise<boolean> { public async joined({userId}: { userId: number }, request: any): Promise<boolean> {
userId = userId ?? request.session.userId; userId = userId ?? request.session.userId;
if (userId) { if (userId) {
const members = await this.$get("rMembers", {where: {id: userId}}) as User[]; const members = await this.$get("rMembers", {where: {id: userId}}) as User[];

@ -50,7 +50,7 @@ export class Post extends Model<Post> {
*/ */
@BelongsToMany(() => User, () => PostVote) @BelongsToMany(() => User, () => PostVote)
// tslint:disable-next-line:completed-docs // tslint:disable-next-line:completed-docs
public rVotes: Array<User & {PostVote: PostVote}>; public rVotes: Array<User & { PostVote: PostVote }>;
/** /**
* The date the post was created at * The date the post was created at
@ -68,15 +68,15 @@ export class Post extends Model<Post> {
/** /**
* Returns the activity of the post. * Returns the activity of the post.
*/ */
public async activity(): Promise<Activity|undefined> { public async activity(): Promise<Activity | undefined> {
return await this.$get("rActivity") as Activity; return await this.$get("rActivity") as Activity;
} }
/** /**
* Returns the votes on a post * Returns the votes on a post
*/ */
public async votes(): Promise<Array<User & {PostVote: PostVote}>> { public async votes(): Promise<Array<User & { PostVote: PostVote }>> {
return await this.$get("rVotes") as Array<User & {PostVote: PostVote}>; return await this.$get("rVotes") as Array<User & { PostVote: PostVote }>;
} }
/** /**
@ -107,12 +107,12 @@ export class Post extends Model<Post> {
*/ */
public async vote(userId: number, type: VoteType): Promise<VoteType> { public async vote(userId: number, type: VoteType): Promise<VoteType> {
type = type ?? VoteType.UPVOTE; type = type ?? VoteType.UPVOTE;
let votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & {PostVote: PostVote}>; let votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & { PostVote: PostVote }>;
let vote = votes[0] ?? null; let vote = votes[0] ?? null;
let created = false; let created = false;
if (!vote) { if (!vote) {
await this.$add("rVote", userId); await this.$add("rVote", userId);
votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & {PostVote: PostVote}>; votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & { PostVote: PostVote }>;
vote = votes[0] ?? null; vote = votes[0] ?? null;
created = true; created = true;
} }
@ -134,10 +134,10 @@ export class Post extends Model<Post> {
* @param userId * @param userId
* @param request * @param request
*/ */
public async userVote({userId}: {userId: number}, request: any): Promise<VoteType> { public async userVote({userId}: { userId: number }, request: any): Promise<VoteType> {
userId = userId ?? request.session.userId; userId = userId ?? request.session.userId;
if (userId) { if (userId) {
const votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & {PostVote: PostVote}>; const votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & { PostVote: PostVote }>;
return votes[0]?.PostVote?.voteType; return votes[0]?.PostVote?.voteType;
} else { } else {
return undefined; return undefined;
@ -149,9 +149,9 @@ export class Post extends Model<Post> {
* @param userId * @param userId
* @param request * @param request
*/ */
public async deletable({userId}: {userId: number}, request: any): Promise<boolean> { public async deletable({userId}: { userId: number }, request: any): Promise<boolean> {
userId = userId ?? request.session.userId; userId = userId ?? request.session.userId;
const isAuthor = Number(userId) === Number(this.authorId); const isAuthor = Number(userId) === Number(this.authorId);
if (userId && !isAuthor) { if (userId && !isAuthor) {
return (await User.findOne({where: {id: userId}})).isAdmin; return (await User.findOne({where: {id: userId}})).isAdmin;
} }

@ -9,8 +9,8 @@ describe("markdown", () => {
expect(result).to.equal("<strong>Hello</strong>"); expect(result).to.equal("<strong>Hello</strong>");
}); });
it("renders markdown emoji", () => { it("renders markdown emoji", () => {
const result = markdown.renderInline(":smile:"); const result = markdown.renderInline(":smile:");
expect(result).to.equal("😄"); expect(result).to.equal("😄");
}); });
}); });
describe("render", () => { describe("render", () => {
@ -19,8 +19,8 @@ describe("markdown", () => {
expect(result).to.equal("<p>#header</p>\n<pre><code></code></pre>\n"); expect(result).to.equal("<p>#header</p>\n<pre><code></code></pre>\n");
}); });
it("renders markdown emoji", () => { it("renders markdown emoji", () => {
const result = markdown.render(":smile:"); const result = markdown.render(":smile:");
expect(result).to.equal("<p>😄</p>\n"); expect(result).to.equal("<p>😄</p>\n");
}); });
}); });
}); });

Loading…
Cancel
Save