Reformatting

This commit is contained in:
powermaker450 2024-09-27 12:04:54 -04:00
parent 550d862e09
commit 4601e06798
11 changed files with 43 additions and 27 deletions

View file

@ -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();

View file

@ -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) {

View file

@ -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) {

View file

@ -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
View file

@ -0,0 +1,2 @@
export * from "./ApiRoute";
export * from "./schemas";

View file

@ -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;

View file

@ -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,

View file

@ -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[];

View file

@ -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,
}; };
} };

View file

@ -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";