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