Reformatting
This commit is contained in:
parent
550d862e09
commit
4601e06798
|
@ -1,8 +1,8 @@
|
|||
import { PostListener, MessagesResponder } from "./routes";
|
||||
import express from "express";
|
||||
import dotenv from "dotenv";
|
||||
import { Logger } from "./utils";
|
||||
import ApiRoute from "./utils/ApiRoute";
|
||||
import { PostListener, MessagesResponder } from "./routes";
|
||||
import Logger from "./utils/Logger";
|
||||
import ApiRoute from "./types/ApiRoute";
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { userReviewSchema, typeJson } from "../types";
|
||||
import { Logger, Responder, data } from "../utils";
|
||||
import { data } from "../utils";
|
||||
import { Express, Request, Response } from "express";
|
||||
import ApiRoute from "../utils/ApiRoute";
|
||||
import ApiRoute from "../types/ApiRoute";
|
||||
import Logger from "../utils/Logger";
|
||||
import Responder from "../utils/Responder";
|
||||
|
||||
export class PostListener extends ApiRoute {
|
||||
constructor(server: Express) {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { Express, Response } from "express";
|
||||
import { Logger, Responder, data } from "../utils";
|
||||
import { IdRequest, ReviewRequest, typeJson } from "../types";
|
||||
import ApiRoute from "../utils/ApiRoute";
|
||||
import { data } from "../utils";
|
||||
import ApiRoute from "../types/ApiRoute";
|
||||
import Logger from "../utils/Logger";
|
||||
import Responder from "../utils/Responder";
|
||||
|
||||
export class MessagesResponder extends ApiRoute {
|
||||
constructor(server: Express) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Express, Request, Response } from "express";
|
||||
import { Logger } from "./logger";
|
||||
import { typeJson } from "../types";
|
||||
import { Responder } from "./responder";
|
||||
import Logger from "../utils/Logger";
|
||||
import Responder from "../utils/Responder";
|
||||
|
||||
export default class ApiRoute {
|
||||
public readonly server: Express;
|
2
src/types/index.ts
Normal file
2
src/types/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from "./ApiRoute";
|
||||
export * from "./schemas";
|
|
@ -1,6 +1,6 @@
|
|||
import chalk from "chalk";
|
||||
|
||||
export class Logger {
|
||||
export default class Logger {
|
||||
private _wrn: string;
|
||||
private _err: string;
|
||||
private _main: string;
|
|
@ -1,6 +1,6 @@
|
|||
import { ValidationError } from "yup";
|
||||
|
||||
export class Responder {
|
||||
export default class Responder {
|
||||
public static success(message: string): string {
|
||||
return JSON.stringify({
|
||||
message: message,
|
|
@ -6,7 +6,6 @@ import {
|
|||
UserSideReview,
|
||||
} from "../types";
|
||||
import { toServerReview, checkFile, stripId } from "./functions";
|
||||
import { Logger } from "./logger";
|
||||
|
||||
export class ReviewData {
|
||||
public data: ServerSideReview[];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as crypto from "crypto";
|
||||
import fs from "fs";
|
||||
import { ServerSideReview, UserSideReview } from "../types";
|
||||
import * as crypto from "crypto";
|
||||
|
||||
export function checkFile(
|
||||
file: string,
|
||||
|
@ -28,23 +28,34 @@ export const generateId = (): string => crypto.randomBytes(3).toString("hex");
|
|||
|
||||
export const getTimestamp = (): string => new Date().toISOString();
|
||||
|
||||
export function toServerReview(userReview: UserSideReview): ServerSideReview {
|
||||
export function toServerReview({
|
||||
rating,
|
||||
username,
|
||||
title,
|
||||
content,
|
||||
}: UserSideReview): ServerSideReview {
|
||||
return {
|
||||
rating: userReview.rating,
|
||||
username: userReview.username,
|
||||
title: userReview.title,
|
||||
content: userReview.content,
|
||||
rating: rating,
|
||||
username: username,
|
||||
title: title,
|
||||
content: content,
|
||||
id: generateId(),
|
||||
timestamp: getTimestamp(),
|
||||
};
|
||||
}
|
||||
|
||||
export function stripId(serverReview: ServerSideReview) {
|
||||
export const stripId = ({
|
||||
rating,
|
||||
username,
|
||||
title,
|
||||
content,
|
||||
timestamp,
|
||||
}: ServerSideReview) => {
|
||||
return {
|
||||
rating: serverReview.rating,
|
||||
username: serverReview.username,
|
||||
title: serverReview.title,
|
||||
content: serverReview.content,
|
||||
timestamp: serverReview.timestamp,
|
||||
rating: rating,
|
||||
username: username,
|
||||
title: title,
|
||||
content: content,
|
||||
timestamp: timestamp,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export * from "./functions";
|
||||
export * from "./logger";
|
||||
export * from "./responder";
|
||||
export * from "./Logger";
|
||||
export * from "./Responder";
|
||||
export * from "./ReviewData";
|
||||
|
|
Loading…
Reference in a new issue