Initialized Project with default middlewares and helpers, connected to Atlas Instance and created Swagger Setup. Created necessary DB models and authentication-authorization logic

This commit is contained in:
Shibi Chakkaravarthy
2026-04-15 02:28:35 +05:30
commit 864e5fae65
71 changed files with 8184 additions and 0 deletions
BIN
View File
Binary file not shown.
+241
View File
@@ -0,0 +1,241 @@
import { Designation } from "../models";
export default {
"/admin/access": {
post: {
tags: ["Admin"],
summary: "Create Access for an Employee",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
user: {
type: "string",
required: true,
},
designation: {
type: "array",
required: true,
},
department: {
type: "string",
required: true,
},
role: {
type: "string",
required: true,
},
branch: {
type: "array",
items: {
type: "string",
},
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/branches": {
get: {
tags: ["Admin"],
summary: "Get All Branches",
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/designations": {
get: {
tags: ["Admin"],
summary: "Get All Designations",
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/departments": {
get: {
tags: ["Admin"],
summary: "Get All Departments",
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/roles": {
get: {
tags: ["Admin"],
summary: "Get All Roles",
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/branch": {
post: {
tags: ["Admin"],
summary: "Create New Branch",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string",
required: true,
},
address: {
type: "string",
required: true,
},
city: {
type: "string",
required: true,
},
state: {
type: "string",
required: true,
},
pincode: {
type: "string",
required: true,
},
coordinates: {
type: "object",
required: true,
properties: {
latitude: {
type: "number",
required: true,
},
longitude: {
type: "number",
required: true,
},
},
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/designation": {
post: {
tags: ["Admin"],
summary: "Create New Designation",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string",
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/department": {
post: {
tags: ["Admin"],
summary: "Create New Department",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string",
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/admin/role": {
post: {
tags: ["Admin"],
summary: "Create New Role",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string",
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
};
+491
View File
@@ -0,0 +1,491 @@
{
"openapi": "3.0.1",
"info": {
"title": "Attica Server Application v1",
"description": "Version 1 of Attica Server Application API",
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
},
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:3000/v0/"
},
{
"url": "https://erp-server.triadkube.com/v0/"
}
],
"security": [
{
"bearerAuth": []
}
],
"components": {
"securitySchemes": {
"bearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
}
},
"paths": {
"/user/create": {
"post": {
"tags": [
"Auth"
],
"summary": "Create Account for New User",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"required": true
},
"id": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/user/login": {
"post": {
"tags": [
"Auth"
],
"summary": "Login with Employee Id and Password",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/user/token/renew": {
"post": {
"tags": [
"Auth"
],
"summary": "Login with Employee Code and Password",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"refreshToken": {
"type": "string",
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/profile": {
"post": {
"tags": [
"Profile"
],
"summary": "Create or Edit Profile New User",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"user": {
"type": "string",
"required": true
},
"mobile": {
"type": "string",
"required": true
},
"address": {
"type": "string",
"required": true
},
"city": {
"type": "string",
"required": true
},
"state": {
"type": "string",
"required": true
},
"pincode": {
"type": "string",
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
},
"get": {
"tags": [
"Profile"
],
"summary": "Get Profile for a User",
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/uploads/single/{folder}": {
"post": {
"tags": [
"Uploads"
],
"summary": "Endpoint to handle Single File",
"parameters": [
{
"in": "path",
"name": "folder"
}
],
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/access": {
"post": {
"tags": [
"Admin"
],
"summary": "Create Access for an Employee",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"user": {
"type": "string",
"required": true
},
"designation": {
"type": "array",
"required": true
},
"department": {
"type": "string",
"required": true
},
"role": {
"type": "string",
"required": true
},
"branch": {
"type": "array",
"items": {
"type": "string"
},
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/branches": {
"get": {
"tags": [
"Admin"
],
"summary": "Get All Branches",
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/designations": {
"get": {
"tags": [
"Admin"
],
"summary": "Get All Designations",
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/departments": {
"get": {
"tags": [
"Admin"
],
"summary": "Get All Departments",
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/roles": {
"get": {
"tags": [
"Admin"
],
"summary": "Get All Roles",
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/branch": {
"post": {
"tags": [
"Admin"
],
"summary": "Create New Branch",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"required": true
},
"address": {
"type": "string",
"required": true
},
"city": {
"type": "string",
"required": true
},
"state": {
"type": "string",
"required": true
},
"pincode": {
"type": "string",
"required": true
},
"coordinates": {
"type": "object",
"required": true,
"properties": {
"latitude": {
"type": "number",
"required": true
},
"longitude": {
"type": "number",
"required": true
}
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/designation": {
"post": {
"tags": [
"Admin"
],
"summary": "Create New Designation",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/department": {
"post": {
"tags": [
"Admin"
],
"summary": "Create New Department",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
},
"/admin/role": {
"post": {
"tags": [
"Admin"
],
"summary": "Create New Role",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"required": true
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
}
}
}
+65
View File
@@ -0,0 +1,65 @@
import path from "path";
import fs from "fs";
import upload from "./upload.js";
import user from "./user.js";
import profile from "./profile.js";
import admin from "./admin.js";
const GENERAL_CONFIG = {
openapi: "3.0.1",
info: {
title: "Attica Server Application v1",
description: "Version 1 of Attica Server Application API",
license: {
name: "MIT",
url: "https://opensource.org/licenses/MIT",
},
version: "1.0.0",
},
servers: [
{
url: "http://localhost:3000/v0/",
},
{
url: "https://erp-server.triadkube.com/v0/",
},
],
security: [
{
bearerAuth: [],
},
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
};
let paths = {
...user,
...profile,
...upload,
...admin,
};
const getSwaggerDocument = () => {
const swaggerDocument = {
...GENERAL_CONFIG,
paths,
};
const fileContent = JSON.stringify(swaggerDocument, null, 2);
const docPath = path.resolve(path.join(__dirname, "documentation.json"));
const existingContent = fs.readFileSync(docPath, "utf8");
if (existingContent !== fileContent) {
console.log("Swagger documentation updated");
fs.writeFileSync(docPath, fileContent);
}
};
export default getSwaggerDocument;
+60
View File
@@ -0,0 +1,60 @@
export default {
"/profile": {
post: {
tags: ["Profile"],
summary: "Create or Edit Profile New User",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
user: {
type: "string",
required: true,
},
mobile: {
type: "string",
required: true,
},
address: {
type: "string",
required: true,
},
city: {
type: "string",
required: true,
},
state: {
type: "string",
required: true,
},
pincode: {
type: "string",
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
get: {
tags: ["Profile"],
summary: "Get Profile for a User",
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
};
+36
View File
@@ -0,0 +1,36 @@
export default {
"/uploads/single/{folder}": {
post: {
tags: ["Uploads"],
summary: "Endpoint to handle Single File",
parameters: [
{
in: "path",
name: "folder",
},
],
requestBody: {
required: true,
content: {
"multipart/form-data": {
schema: {
type: "object",
properties: {
file: {
type: "string",
format: "binary",
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
};
+98
View File
@@ -0,0 +1,98 @@
export default {
"/user/create": {
post: {
tags: ["Auth"],
summary: "Create Account for New User",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string",
required: true,
},
id: {
type: "string",
required: true,
},
password: {
type: "string",
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/user/login": {
post: {
tags: ["Auth"],
summary: "Login with Employee Id and Password",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
id: {
type: "string",
required: true,
},
password: {
type: "string",
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
"/user/token/renew": {
post: {
tags: ["Auth"],
summary: "Login with Employee Code and Password",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
refreshToken: {
type: "string",
required: true,
},
},
},
},
},
},
responses: {
200: {
description: "OK",
content: {},
},
},
},
},
};