diff --git a/README.md b/README.md index f964258..844ddf8 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,4 @@ docker compose -f docker-compose.dev.yml up #### Supported Services - MongoDB -- Redis \ No newline at end of file +- Redis diff --git a/__test__/models/post.model.test.ts b/__test__/models/post.model.test.ts index 6e082fe..de294eb 100644 --- a/__test__/models/post.model.test.ts +++ b/__test__/models/post.model.test.ts @@ -1,18 +1,24 @@ -import Post from '../../src/models/post.model' +import Post from "../../src/models/post.model"; -describe('Post model', () => { - describe('validation', () => { - test('should validate a post', async function () { - await expect(new Post({ - title: 'Lorem ipsum', - content: 'Lorem ipsum' - }).validate()).resolves.toBeUndefined() - }) - test('should have a title', async () => { - await expect(new Post({ title: undefined, content: '' }).validate()).rejects.toThrow() - }) - test('should have content', async () => { - await expect(new Post({ title: '', content: undefined }).validate()).rejects.toThrow() - }) - }) -}) \ No newline at end of file +describe("Post model", () => { + describe("validation", () => { + test("should validate a post", async function () { + await expect( + new Post({ + title: "Lorem ipsum", + content: "Lorem ipsum", + }).validate() + ).resolves.toBeUndefined(); + }); + test("should have a title", async () => { + await expect( + new Post({ title: undefined, content: "" }).validate() + ).rejects.toThrow(); + }); + test("should have content", async () => { + await expect( + new Post({ title: "", content: undefined }).validate() + ).rejects.toThrow(); + }); + }); +}); diff --git a/src/config/env.ts b/src/config/env.ts index 1e258a4..30ad8fd 100644 --- a/src/config/env.ts +++ b/src/config/env.ts @@ -1,29 +1,34 @@ -import Joi from 'joi' +import Joi from "joi"; -const schema = Joi - .object() +const schema = Joi.object() .keys({ PORT: Joi.number().required().default(3000), - MONGODB_HOST: Joi.string().required().example('localhost'), + MONGODB_HOST: Joi.string().required().example("localhost"), MONGODB_PORT: Joi.number().required().example(27017), - MONGODB_USER: Joi.string().required().example('root'), - MONGODB_PASS: Joi.string().required().example('pass'), - MONGODB_NAME: Joi.string().optional().example('db'), - REDIS_QUEUE_HOST: Joi.string().optional().example('localhost'), - REDIS_QUEUE_PORT: Joi.number().optional().example(6379) + MONGODB_USER: Joi.string().required().example("root"), + MONGODB_PASS: Joi.string().required().example("pass"), + MONGODB_NAME: Joi.string().optional().example("db"), + REDIS_QUEUE_HOST: Joi.string().optional().example("localhost"), + REDIS_QUEUE_PORT: Joi.number().optional().example(6379), }) - .unknown() + .unknown(); -const { value: env, error } = schema.prefs({ errors: { label: 'key' } }).validate(process.env) +const { value: env, error } = schema + .prefs({ errors: { label: "key" } }) + .validate(process.env); if (error != null) { - throw new Error(`Config validation error: ${error.message}`) + throw new Error(`Config validation error: ${error.message}`); } // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -const MONGODB_URL = `mongodb://${env.MONGODB_USER}:${env.MONGODB_PASS}@${env.MONGODB_HOST}:${env.MONGODB_PORT}/${env.MONGODB_NAME !== undefined ? env.MONGODB_NAME : ''}` +const MONGODB_URL = `mongodb://${env.MONGODB_USER}:${env.MONGODB_PASS}@${ + env.MONGODB_HOST +}:${env.MONGODB_PORT}/${ + env.MONGODB_NAME !== undefined ? env.MONGODB_NAME : "" +}`; export default { ...env, - MONGODB_URL -} \ No newline at end of file + MONGODB_URL, +}; diff --git a/src/index.ts b/src/index.ts index 45a6506..e03fe7f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,14 +2,18 @@ import mongoose from "mongoose"; import app from "./app"; import { env } from "./config"; -mongoose.set('strictQuery', true) +mongoose.set("strictQuery", true); -main().catch(err => { console.error(err) }) +main().catch((err) => { + console.error(err); +}); -async function main (): Promise { - await mongoose.connect(env.MONGODB_URL) +async function main(): Promise { + await mongoose.connect(env.MONGODB_URL); app.listen(env.PORT, () => { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - console.log(`⚡️[server]: Server is running at http://localhost:${env.PORT}`) - }) -} \ No newline at end of file + console.log( + `⚡️[server]: Server is running at http://localhost:${env.PORT}` + ); + }); +} diff --git a/src/models/post.model.ts b/src/models/post.model.ts index 23875d9..b8e0064 100644 --- a/src/models/post.model.ts +++ b/src/models/post.model.ts @@ -1,16 +1,16 @@ -import mongoose from 'mongoose' +import mongoose from "mongoose"; const schema = new mongoose.Schema({ title: { type: String, - required: true + required: true, }, content: { type: String, - required: true - } -}) + required: true, + }, +}); -const model = mongoose.model('Post', schema) +const model = mongoose.model("Post", schema); -export default model \ No newline at end of file +export default model; diff --git a/tsconfig.json b/tsconfig.json index 3353882..1865b5a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, - "skipLibCheck": true, + "skipLibCheck": true }, "include": [ "./src/**/*",