mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-10 03:39:44 -06:00
Update auth endpoints
This commit is contained in:
@@ -49,23 +49,6 @@ const registerController = async (req, res, next) => {
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Can there be more than one admin?
|
||||
// // Check if an admin user exists, if so, error
|
||||
// try {
|
||||
// const admin = await req.db.checkAdmin(req, res);
|
||||
// console.log(admin);
|
||||
// if (admin === true) {
|
||||
// throw new Error(errorMessages.AUTH_ADMIN_EXISTS);
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.log("WEEEEEEE", error.message);
|
||||
// error.service = SERVICE_NAME;
|
||||
// error.status = 403;
|
||||
// next(error);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Create a new user
|
||||
try {
|
||||
const newUser = await req.db.insertUser({ ...req.body }, req.file);
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const swaggerUi = require("swagger-ui-express");
|
||||
|
||||
const express = require("express");
|
||||
const helmet = require("helmet");
|
||||
const cors = require("cors");
|
||||
@@ -21,8 +25,11 @@ const NetworkService = require("./service/networkService");
|
||||
const EmailService = require("./service/emailService");
|
||||
const PageSpeedService = require("./service/pageSpeedService");
|
||||
const SERVICE_NAME = "Server";
|
||||
let cleaningUp = false;
|
||||
|
||||
let cleaningUp = false;
|
||||
const openApiSpec = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, "openapi.json"), "utf8")
|
||||
);
|
||||
// Need to wrap server setup in a function to handle async nature of JobQueue
|
||||
const startApp = async () => {
|
||||
// **************************
|
||||
@@ -70,6 +77,9 @@ const startApp = async () => {
|
||||
next();
|
||||
});
|
||||
|
||||
// Swagger UI
|
||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(openApiSpec));
|
||||
|
||||
//routes
|
||||
app.use("/api/v1/auth", authRouter);
|
||||
app.use("/api/v1/invite", inviteRouter);
|
||||
|
||||
@@ -81,7 +81,14 @@
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": ["firstName", "lastName", "email", "password", "role", "teamId"],
|
||||
"required": [
|
||||
"firstName",
|
||||
"lastName",
|
||||
"email",
|
||||
"password",
|
||||
"role",
|
||||
"teamId"
|
||||
],
|
||||
"properties": {
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
@@ -103,7 +110,7 @@
|
||||
},
|
||||
"role": {
|
||||
"type": "array",
|
||||
"enum": [["user"], ["admin"], ["superadmin"]],
|
||||
"enum": [["user"], ["admin"], ["superadmin"], ["Demo"]],
|
||||
"default": ["superadmin"]
|
||||
},
|
||||
"teamId": {
|
||||
@@ -207,78 +214,54 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/user/:userId": {
|
||||
"/auth/user/{userId}": {
|
||||
"put": {
|
||||
"tags": ["auth"],
|
||||
"description": "Change user informations",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/UserSuccessResponse"
|
||||
}
|
||||
}
|
||||
"description": "Change user information",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "userId",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Unprocessable Content",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ErrorResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ErrorResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/UserUpdateRequest"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"tags": ["auth"],
|
||||
"description": "Delete user",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/UserSuccessResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Unprocessable Content",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ErrorResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ErrorResponse"
|
||||
}
|
||||
}
|
||||
"parameters": [
|
||||
{
|
||||
"name": "userId",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/auth/users/admin": {
|
||||
@@ -587,12 +570,20 @@
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"securitySchemes": {
|
||||
"bearerAuth": {
|
||||
"type": "http",
|
||||
"scheme": "bearer",
|
||||
"bearerFormat": "JWT"
|
||||
}
|
||||
},
|
||||
"schemas": {
|
||||
"ErrorResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"msg": {
|
||||
"type": "string"
|
||||
@@ -613,6 +604,45 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"UserUpdateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"firstName",
|
||||
"lastName",
|
||||
"email",
|
||||
"password",
|
||||
"role",
|
||||
"teamId"
|
||||
],
|
||||
"properties": {
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string",
|
||||
"format": "password"
|
||||
},
|
||||
"newPassword": {
|
||||
"type": "string",
|
||||
"format": "password"
|
||||
},
|
||||
"profileImage": {
|
||||
"type": "file",
|
||||
"format": "file"
|
||||
},
|
||||
"role": {
|
||||
"type": "array",
|
||||
"enum": [["user"], ["admin"], ["superadmin"], ["Demo"]],
|
||||
"default": ["superadmin"]
|
||||
},
|
||||
"deleteProfileImage": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"UserSuccessResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Reference in New Issue
Block a user