diff --git a/src/lib/UploadManager.ts b/src/lib/UploadManager.ts index 307ea70..223ea89 100644 --- a/src/lib/UploadManager.ts +++ b/src/lib/UploadManager.ts @@ -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"; /** diff --git a/src/lib/dataAccess.ts b/src/lib/dataAccess.ts index e821e4e..668c8b1 100644 --- a/src/lib/dataAccess.ts +++ b/src/lib/dataAccess.ts @@ -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 ? diff --git a/src/lib/models/Group.ts b/src/lib/models/Group.ts index 41a7c01..245003f 100644 --- a/src/lib/models/Group.ts +++ b/src/lib/models/Group.ts @@ -1,10 +1,9 @@ -import * as sqz from "sequelize"; import { BelongsTo, BelongsToMany, Column, ForeignKey, - HasMany, HasOne, + HasMany, Model, NotNull, Table, diff --git a/src/lib/models/Media.ts b/src/lib/models/Media.ts index a9440d5..1d3a58d 100644 --- a/src/lib/models/Media.ts +++ b/src/lib/models/Media.ts @@ -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 { diff --git a/src/lib/models/Post.ts b/src/lib/models/Post.ts index c39c545..cda62d3 100644 --- a/src/lib/models/Post.ts +++ b/src/lib/models/Post.ts @@ -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"; diff --git a/src/lib/models/User.ts b/src/lib/models/User.ts index a98fc88..7fbe1f5 100644 --- a/src/lib/models/User.ts +++ b/src/lib/models/User.ts @@ -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 { 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[]; } /** diff --git a/src/routes/UploadRoute.ts b/src/routes/UploadRoute.ts index 2899788..76b7a76 100644 --- a/src/routes/UploadRoute.ts +++ b/src/routes/UploadRoute.ts @@ -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"; diff --git a/src/routes/graphql/MutationResolver.ts b/src/routes/graphql/MutationResolver.ts index c54db01..aea1be2 100644 --- a/src/routes/graphql/MutationResolver.ts +++ b/src/routes/graphql/MutationResolver.ts @@ -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 { this.ensureLoggedIn(request); if (content.length > 2048) {