1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-07 06:30:06 +00:00

chore: restructured controllers

This commit is contained in:
Saad Jutt
2021-11-11 03:40:57 +05:00
parent 7a8123eb52
commit 1814c3a1f4
27 changed files with 84 additions and 66 deletions

View File

@@ -2,11 +2,17 @@ import { Security, Route, Tags, Example, Post, Body, Query, Hidden } from 'tsoa'
import jwt from 'jsonwebtoken'
import User from '../model/User'
import { InfoJWT } from '../types'
import { removeTokensInDB, saveTokensInDB } from '../utils'
import {
generateAccessToken,
generateAuthCode,
generateRefreshToken,
removeTokensInDB,
saveTokensInDB
} from '../utils'
@Route('SASjsApi/auth')
@Tags('Auth')
export default class AuthController {
export class AuthController {
static authCodes: { [key: string]: { [key: string]: string } } = {}
static saveCode = (userId: number, clientId: string, code: string) => {
if (AuthController.authCodes[userId])
@@ -185,21 +191,6 @@ interface TokenResponse {
refreshToken: string
}
export const generateAuthCode = (data: InfoJWT) =>
jwt.sign(data, process.env.AUTH_CODE_SECRET as string, {
expiresIn: '30s'
})
export const generateAccessToken = (data: InfoJWT) =>
jwt.sign(data, process.env.ACCESS_TOKEN_SECRET as string, {
expiresIn: '1h'
})
export const generateRefreshToken = (data: InfoJWT) =>
jwt.sign(data, process.env.REFRESH_TOKEN_SECRET as string, {
expiresIn: '1day'
})
const verifyAuthCode = async (
clientId: string,
code: string

View File

@@ -5,7 +5,7 @@ import Client, { ClientPayload } from '../model/Client'
@Security('bearerAuth')
@Route('SASjsApi/client')
@Tags('Client')
export default class ClientController {
export class ClientController {
/**
* @summary Create client with the following attributes: ClientId, ClientSecret. Admin only task.
*

View File

@@ -11,7 +11,7 @@ import {
Patch
} from 'tsoa'
import { fileExists, readFile, createFile } from '@sasjs/utils'
import { createFileTree, ExecutionController, getTreeExample } from '.'
import { createFileTree, ExecutionController, getTreeExample } from './internal'
import { FileTree, isFileTree, TreeNode } from '../types'
import path from 'path'

View File

@@ -31,7 +31,7 @@ interface GroupDetailsResponse {
@Security('bearerAuth')
@Route('SASjsApi/group')
@Tags('Group')
export default class GroupController {
export class GroupController {
/**
* @summary Get list of all groups (groupName and groupDescription). All users can request this.
*

View File

@@ -1,4 +1,6 @@
export * from './deploy'
export * from './Session'
export * from './Execution'
export * from './FileUploadController'
export * from './auth'
export * from './client'
export * from './drive'
export * from './group'
export * from './stp'
export * from './user'

View File

@@ -2,11 +2,11 @@ import path from 'path'
import fs from 'fs'
import { getSessionController } from './'
import { readFile, fileExists, createFile } from '@sasjs/utils'
import { configuration } from '../../package.json'
import { configuration } from '../../../package.json'
import { promisify } from 'util'
import { execFile } from 'child_process'
import { PreProgramVars, Session, TreeNode } from '../types'
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../utils'
import { PreProgramVars, Session, TreeNode } from '../../types'
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../../utils'
const execFilePromise = promisify(execFile)

View File

@@ -1,5 +1,5 @@
import { Session } from '../types'
import { getTmpSessionsFolderPath, generateUniqueFileName } from '../utils'
import { Session } from '../../types'
import { getTmpSessionsFolderPath, generateUniqueFileName } from '../../utils'
import {
deleteFolder,
createFile,
@@ -120,7 +120,7 @@ export class SessionController {
}
}
export const getSessionController = () => {
export const getSessionController = (): SessionController => {
if (process.sessionController) return process.sessionController
process.sessionController = new SessionController()

View File

@@ -1,5 +1,5 @@
import { MemberType, FolderMember, ServiceMember, FileTree } from '../types'
import { getTmpFilesFolderPath } from '../utils/file'
import { MemberType, FolderMember, ServiceMember, FileTree } from '../../types'
import { getTmpFilesFolderPath } from '../../utils/file'
import { createFolder, createFile, asyncForEach } from '@sasjs/utils'
import path from 'path'

View File

@@ -0,0 +1,4 @@
export * from './deploy'
export * from './Session'
export * from './Execution'
export * from './FileUploadController'

View File

@@ -11,7 +11,7 @@ import {
Get,
Query
} from 'tsoa'
import { ExecutionController } from '.'
import { ExecutionController } from './internal'
import { PreProgramVars } from '../types'
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
@@ -32,7 +32,7 @@ interface ExecuteReturnJsonResponse {
@Security('bearerAuth')
@Route('SASjsApi/client')
@Tags('STP')
export default class STPController {
export class STPController {
/**
* Trigger a SAS program using it's location in the _program parameter.
* Enable debugging using the _debug parameter.

View File

@@ -32,7 +32,7 @@ interface UserDetailsResponse {
@Security('bearerAuth')
@Route('SASjsApi/user')
@Tags('User')
export default class UserController {
export class UserController {
/**
* @summary Get list of all users (username, displayname). All users can request this.
*