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 * as sharp from "sharp";
import {Readable} from "stream"; import {Readable} from "stream";
import globals from "./globals"; import globals from "./globals";
import {Media} from "./models/Media"; import {Media} from "./models";
const toArray = require("stream-to-array"); const toArray = require("stream-to-array");
@ -19,23 +19,6 @@ export enum MediaType {
VIDEO = "VIDEO", 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"; type ImageFit = "cover" | "contain" | "fill" | "inside" | "outside";
/** /**

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

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

@ -6,6 +6,9 @@ import {Group} from "./Group";
import {Post} from "./Post"; import {Post} from "./Post";
import {User} from "./User"; 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}) @Table({underscored: true})
export class Media extends Model<Media> { export class Media extends Model<Media> {

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

@ -3,8 +3,9 @@ import {
BelongsTo, BelongsTo,
BelongsToMany, BelongsToMany,
Column, Column,
CreatedAt, ForeignKey, CreatedAt,
HasMany, HasOne, ForeignKey,
HasMany,
Model, Model,
NotNull, NotNull,
Table, Table,
@ -311,9 +312,9 @@ export class User extends Model<User> {
const limit = first ?? 10; const limit = first ?? 10;
offset = offset ?? 0; offset = offset ?? 0;
if (request.session.userId === this.getDataValue("id")) { 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 config from "config";
import * as crypto from "crypto"; import * as crypto from "crypto";
import {Router} from "express"; import {Router} from "express";
import {UploadedFile} from "express-fileupload";
import * as fileUpload from "express-fileupload"; import * as fileUpload from "express-fileupload";
import {UploadedFile} from "express-fileupload";
import * as fsx from "fs-extra"; import * as fsx from "fs-extra";
import * as status from "http-status"; import * as status from "http-status";
import * as path from "path"; import * as path from "path";
import globals from "../lib/globals"; import globals from "../lib/globals";
import {Group, Post, User} from "../lib/models"; import {Group, Post, User} from "../lib/models";
import {Media} from "../lib/models/Media"; import {Media} from "../lib/models";
import {is} from "../lib/regex"; import {is} from "../lib/regex";
import Route from "../lib/Route"; import Route from "../lib/Route";
import {UploadManager} from "../lib/UploadManager"; import {UploadManager} from "../lib/UploadManager";

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

Loading…
Cancel
Save