update swagger done

This commit is contained in:
2024-11-27 07:44:45 +07:00
parent d5cd47f17a
commit 4a8fde1640
10 changed files with 477 additions and 255 deletions

View File

@ -19,15 +19,17 @@ export class AuthController {
static async login(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['Auth']
#swagger.parameters['body'] = {
in: 'body',
description: 'Login data',
#swagger.requestBody = {
required: true,
schema: {
username: "admin",
password: "123456"
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/login"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({
@ -35,9 +37,6 @@ export class AuthController {
password: Joi.string().alphanum().min(6).required().label('Password')
});
console.log('req.body', req.body)
console.log('req', req)
const param: User = await schema.validateAsync(req.body);
const userRepository = OrmHelper.DB.getRepository(User);

View File

@ -44,7 +44,9 @@ export class UserController {
#swagger.parameters['order_direction'] = {
in: 'query',
required: true,
enum: [ "ASC", "DESC"]
schema: {
'@enum': ['ASC', 'DESC']
}
}
*/
@ -103,23 +105,21 @@ export class UserController {
static async create(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User']
#swagger.security = [{
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['body'] = {
in: 'body',
description: 'User data',
#swagger.requestBody = {
required: true,
schema: {
email: "admin@gmail.com",
username: "admin",
password: "123456",
retype_password: "123456",
name: "Administrator",
id_role: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
status:"Y"
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({
@ -158,7 +158,7 @@ export class UserController {
static async updateProfile(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User']
#swagger.security = [{
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {
@ -168,16 +168,17 @@ export class UserController {
type: 'string'
}
#swagger.parameters['body'] = {
in: 'body',
description: 'User data',
#swagger.requestBody = {
required: true,
schema: {
email: "admin@gmail.com",
username: "admin",
name: "Administrator"
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user_profile"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({
@ -217,7 +218,7 @@ export class UserController {
static async updatePassword(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User']
#swagger.security = [{
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {
@ -227,15 +228,17 @@ export class UserController {
type: 'string'
}
#swagger.parameters['body'] = {
in: 'body',
description: 'User data',
#swagger.requestBody = {
required: true,
schema: {
password: "123456",
retype_password: "123456",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user_password"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({
@ -275,7 +278,7 @@ export class UserController {
static async update(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User']
#swagger.security = [{
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {
@ -285,20 +288,17 @@ export class UserController {
type: 'string'
}
#swagger.parameters['body'] = {
in: 'body',
description: 'User data',
#swagger.requestBody = {
required: true,
schema: {
email: "admin@gmail.com",
username: "admin",
password: "123456",
retype_password: "123456",
name: "Administrator",
id_role: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
status:"Y"
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({
@ -349,7 +349,7 @@ export class UserController {
static async delete(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User']
#swagger.security = [{
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {
@ -386,7 +386,7 @@ export class UserController {
static async restore(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User']
#swagger.security = [{
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {

View File

@ -16,6 +16,9 @@ export class UserActivityController {
static async list(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Activity']
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['filter'] = {
in: 'query',
type: 'string'
@ -102,20 +105,21 @@ export class UserActivityController {
static async create(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Activity']
#swagger.parameters['body'] = {
in: 'body',
description: 'User Activity data',
#swagger.security = [{
"bearerAuth": []
}]
#swagger.requestBody = {
required: true,
schema: {
id_user: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
refresh_token: "1a1221b6-78a0-4b3b-bf5c-fa0af5f69be8",
module: "dashboard",
description: "Main Dashboard",
action: "V",
url: "https://bri-dev.shiblysolution.id/",
data_body:"{\"from\":\"2024-11-01\",\"to\":\"2024-11-26\"}"
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user_activity"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({

View File

@ -1,4 +1,5 @@
import { Request, Response, NextFunction, Application } from "express";
import { Response, NextFunction, Application } from "express";
import { Request } from "express-jwt";
import { ReturnHelper } from "../helpers/express/return";
import { OrmHelper } from "../helpers/orm";
import Joi from "joi";
@ -14,6 +15,9 @@ export class UserRefreshTokenController {
static async list(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Refresh Token']
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['filter'] = {
in: 'query',
type: 'string'
@ -59,11 +63,14 @@ export class UserRefreshTokenController {
let whereVal: any = {};
if (param.filter) {
whereAttr = 'name like :filter_like or username like :filter_like or email = :filter ';
whereAttr = '(name like :filter_like or username like :filter_like or email = :filter) and ';
whereVal['filter'] = param.filter
whereVal['filter_like'] = '%' + param.filter + '%'
}
whereAttr += 'id_user = :id_user'
whereVal['id_user'] = req.auth.data.id;
const res_count = repo.createQueryBuilder()
.where(whereAttr, whereVal);
const res_list = repo.createQueryBuilder()

View File

@ -8,6 +8,7 @@ import { Paging } from "../types/paging";
import CommonHelper from "../helpers/common";
import { Status } from "../types/status";
import { UserRole } from "../entity/users_roles";
import { RoleList } from "../types/role";
const log: Logger<ILogObj> = new Logger({ name: '[UserRoleController]', type: 'pretty' });
@ -15,6 +16,9 @@ export class UserRoleController {
static async list(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Roles']
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['filter'] = {
in: 'query',
type: 'string'
@ -98,19 +102,46 @@ export class UserRoleController {
}
}
static async role(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Roles']
#swagger.security = [{
"bearerAuth": []
}]
*/
try {
const current_page = 1;
const total_count_data = CommonHelper.countObject(RoleList);
const list_data = CommonHelper.objectFlip(RoleList);
const count_data = CommonHelper.countObject(RoleList);
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, list_data);
} catch (e: unknown) {
log.error(e);
const err = e as Error;
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message);
}
}
static async create(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Roles']
#swagger.parameters['body'] = {
in: 'body',
description: 'User role data',
#swagger.security = [{
"bearerAuth": []
}]
#swagger.requestBody = {
required: true,
schema: {
name: "Administrator",
roles: ["dashboard"],
status:"Y"
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user_role"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({
@ -140,6 +171,9 @@ export class UserRoleController {
static async update(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Roles']
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {
in: 'path',
description: 'User role ID.',
@ -147,16 +181,17 @@ export class UserRoleController {
type: 'string'
}
#swagger.parameters['body'] = {
in: 'body',
description: 'User role data',
#swagger.requestBody = {
required: true,
schema: {
name: "Administrator",
roles: ["dashboard"],
status:"Y"
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/user_role"
}
}
}
}*/
}
*/
try {
const schema = Joi.object().keys({
@ -196,6 +231,9 @@ export class UserRoleController {
static async delete(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Roles']
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {
in: 'path',
description: 'User role ID.',
@ -230,6 +268,9 @@ export class UserRoleController {
static async restore(req: Request, res: Response, next: NextFunction): Promise<Response> {
/*
#swagger.tags = ['User Roles']
#swagger.security = [{
"bearerAuth": []
}]
#swagger.parameters['id'] = {
in: 'path',
description: 'User role ID.',