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

View file

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

View file

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

View file

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

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

View file

@ -1,6 +1,6 @@
import chalk from "chalk";
export class Logger {
export default class Logger {
private _wrn: string;
private _err: string;
private _main: string;

View file

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

View file

@ -6,7 +6,6 @@ import {
UserSideReview,
} from "../types";
import { toServerReview, checkFile, stripId } from "./functions";
import { Logger } from "./logger";
export class ReviewData {
public data: ServerSideReview[];

View file

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

View file

@ -1,4 +1,4 @@
export * from "./functions";
export * from "./logger";
export * from "./responder";
export * from "./Logger";
export * from "./Responder";
export * from "./ReviewData";