diff --git a/src/controllers/AuthControler.ts b/src/controllers/AuthControler.ts index 5d0e43e..0d0e95d 100644 --- a/src/controllers/AuthControler.ts +++ b/src/controllers/AuthControler.ts @@ -1,5 +1,5 @@ import jwt from "jsonwebtoken"; -import AppModel from "../models/AppModel"; +import AuthService from "../services/AuthService"; import { Request, Response, NextFunction } from "express"; const authTokenSecret = process.env.JWTSECRET || "badsecret"; @@ -10,7 +10,7 @@ class AuthControler { const { app, secret } = req.body; // Filter app from the apps by app and secret - const authenticated = await AppModel.findOne(app, secret); + const authenticated = await AuthService.find(app, secret); if (authenticated) { console.log("Authenticated app ", authenticated.app); diff --git a/src/models/AppModel.ts b/src/models/AuthModel.ts similarity index 59% rename from src/models/AppModel.ts rename to src/models/AuthModel.ts index 9ef6535..52dc172 100644 --- a/src/models/AppModel.ts +++ b/src/models/AuthModel.ts @@ -1,11 +1,11 @@ import mongoose, { Document } from "mongoose"; -export interface App extends Document { +export interface Auth extends Document { app: String, secret: String } -const AppSchema = new mongoose.Schema({ +const AuthSchema = new mongoose.Schema({ app: { type: String, required: true, @@ -16,4 +16,4 @@ const AppSchema = new mongoose.Schema({ }, }); -export default mongoose.model("apps", AppSchema); +export default mongoose.model("auth", AuthSchema); diff --git a/src/services/AuthService.ts b/src/services/AuthService.ts new file mode 100644 index 0000000..1b4bb62 --- /dev/null +++ b/src/services/AuthService.ts @@ -0,0 +1,9 @@ +import AuthModel, { Auth } from "../models/AuthModel"; + +class AuthService { + async find(app: String, secret: String): Promise { + return await AuthModel.findOne(app, secret); + } +} + +export default new AuthService();