Cleanup code

- Cleanup
- Optimization
- Style fixes
pull/4/head
trivernis 5 years ago
parent 6ede632507
commit 0e232b1c71

@ -5,7 +5,7 @@ import * as path from "path";
import * as sharp from "sharp";
import {Readable} from "stream";
import globals from "./globals";
import {Media} from "./models/Media";
import {Media} from "./models";
const toArray = require("stream-to-array");
@ -19,23 +19,6 @@ export enum MediaType {
VIDEO = "VIDEO",
}
interface IUploadConfirmation {
/**
* Indicates the error that might have occured during the upload
*/
error?: string;
/**
* The file that has been uploaded
*/
fileName?: string;
/**
* If the upload was successful
*/
success: boolean;
}
type ImageFit = "cover" | "contain" | "fill" | "inside" | "outside";
/**

@ -191,10 +191,12 @@ namespace dataaccess {
SELECT *,
(SELECT count(*)
FROM post_votes
WHERE vote_type = 'UPVOTE' AND post_id = posts.id) AS upvotes,
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
WHERE vote_type = 'DOWNVOTE'
AND post_id = posts.id) AS downvotes
FROM posts) AS a
ORDER BY (a.upvotes - a.downvotes) DESC, a.upvotes DESC, a.id
LIMIT ?

@ -1,10 +1,9 @@
import * as sqz from "sequelize";
import {
BelongsTo,
BelongsToMany,
Column,
ForeignKey,
HasMany, HasOne,
HasMany,
Model,
NotNull,
Table,

@ -6,6 +6,9 @@ import {Group} from "./Group";
import {Post} from "./Post";
import {User} from "./User";
/**
* Represents a single media file that can be used as a profile picture for groups and users or a post picture
*/
@Table({underscored: true})
export class Media extends Model<Media> {

@ -1,18 +1,6 @@
import * as config from "config";
import * as sqz from "sequelize";
import {
BelongsTo,
BelongsToMany,
Column,
CreatedAt,
ForeignKey,
HasOne,
Model,
NotNull,
Table,
} from "sequelize-typescript";
import {BelongsTo, BelongsToMany, Column, CreatedAt, ForeignKey, Model, NotNull, Table} from "sequelize-typescript";
import markdown from "../markdown";
import {MediaType} from "../UploadManager";
import {Activity} from "./Activity";
import {Media} from "./Media";
import {PostVote, VoteType} from "./PostVote";

@ -3,8 +3,9 @@ import {
BelongsTo,
BelongsToMany,
Column,
CreatedAt, ForeignKey,
HasMany, HasOne,
CreatedAt,
ForeignKey,
HasMany,
Model,
NotNull,
Table,
@ -311,9 +312,9 @@ export class User extends Model<User> {
const limit = first ?? 10;
offset = offset ?? 0;
if (request.session.userId === this.getDataValue("id")) {
return await this.$get("rPosts", { limit, offset, order: [["id", "desc"]]}) as Post[];
return await this.$get("rPosts", {limit, offset, order: [["id", "desc"]]}) as Post[];
}
return await this.$get("rPosts", { limit, offset, where: {visible: true}, order: [["id", "desc"]]}) as Post[];
return await this.$get("rPosts", {limit, offset, where: {visible: true}, order: [["id", "desc"]]}) as Post[];
}
/**

@ -2,14 +2,14 @@ import * as bodyParser from "body-parser";
import * as config from "config";
import * as crypto from "crypto";
import {Router} from "express";
import {UploadedFile} from "express-fileupload";
import * as fileUpload from "express-fileupload";
import {UploadedFile} from "express-fileupload";
import * as fsx from "fs-extra";
import * as status from "http-status";
import * as path from "path";
import globals from "../lib/globals";
import {Group, Post, User} from "../lib/models";
import {Media} from "../lib/models/Media";
import {Media} from "../lib/models";
import {is} from "../lib/regex";
import Route from "../lib/Route";
import {UploadManager} from "../lib/UploadManager";

@ -1,12 +1,10 @@
import {GraphQLError} from "graphql";
import {FileUpload} from "graphql-upload";
import * as yaml from "js-yaml";
import isEmail from "validator/lib/isEmail";
import dataAccess from "../../lib/dataAccess";
import {BlacklistedError} from "../../lib/errors/BlacklistedError";
import {GroupNotFoundError} from "../../lib/errors/GroupNotFoundError";
import {InvalidEmailError} from "../../lib/errors/InvalidEmailError";
import {InvalidFileError} from "../../lib/errors/InvalidFileError";
import {NotAGroupAdminError} from "../../lib/errors/NotAGroupAdminError";
import {NotAnAdminError} from "../../lib/errors/NotAnAdminError";
import {NotTheGroupCreatorError} from "../../lib/errors/NotTheGroupCreatorError";
@ -14,7 +12,6 @@ import {PostNotFoundError} from "../../lib/errors/PostNotFoundError";
import globals from "../../lib/globals";
import {InternalEvents} from "../../lib/InternalEvents";
import {Activity, BlacklistedPhrase, ChatMessage, ChatRoom, Event, Group, Post, Request, User} from "../../lib/models";
import {is} from "../../lib/regex";
import {UploadManager} from "../../lib/UploadManager";
import {BaseResolver} from "./BaseResolver";
@ -147,7 +144,7 @@ export class MutationResolver extends BaseResolver {
* @param request
*/
public async createPost(
{content, activityId, type}: { content: string, activityId?: number, type: dataAccess.PostType},
{content, activityId, type}: { content: string, activityId?: number, type: dataAccess.PostType },
request: any): Promise<Post> {
this.ensureLoggedIn(request);
if (content.length > 2048) {

Loading…
Cancel
Save