mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-20 02:20:05 +00:00
chore: code refactored for better readability
This commit is contained in:
63
src/SASjs.ts
63
src/SASjs.ts
@@ -547,7 +547,7 @@ export default class SASjs {
|
|||||||
*/
|
*/
|
||||||
public async request(
|
public async request(
|
||||||
sasJob: string,
|
sasJob: string,
|
||||||
data: { [key: string]: any },
|
data: { [key: string]: any } | null,
|
||||||
config: { [key: string]: any } = {},
|
config: { [key: string]: any } = {},
|
||||||
loginRequiredCallback?: () => any,
|
loginRequiredCallback?: () => any,
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
@@ -576,7 +576,8 @@ export default class SASjs {
|
|||||||
data,
|
data,
|
||||||
config,
|
config,
|
||||||
loginRequiredCallback,
|
loginRequiredCallback,
|
||||||
accessToken
|
accessToken,
|
||||||
|
extraResponseAttributes
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
@@ -606,45 +607,45 @@ export default class SASjs {
|
|||||||
* @param data a json object contains one or more table, it can also be null
|
* @param data a json object contains one or more table, it can also be null
|
||||||
* @returns a object which contains two attributes: 1) status: boolean, 2) msg: string
|
* @returns a object which contains two attributes: 1) status: boolean, 2) msg: string
|
||||||
*/
|
*/
|
||||||
private validateInput(data: { [key: string]: any }): {
|
private validateInput(data: { [key: string]: any } | null): {
|
||||||
status: boolean
|
status: boolean
|
||||||
msg: string
|
msg: string
|
||||||
} {
|
} {
|
||||||
if (data === null) return { status: true, msg: '' }
|
if (data === null) return { status: true, msg: '' }
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
if (key.match(/^[a-zA-Z_]/)) {
|
if (!key.match(/^[a-zA-Z_]/)) {
|
||||||
if (key.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)) {
|
|
||||||
if (key.length <= 32) {
|
|
||||||
if (this.getType(data[key]) === 'Array') {
|
|
||||||
for (let i = 0; i < data[key].length; i++) {
|
|
||||||
if (this.getType(data[key][i]) !== 'object') {
|
|
||||||
return {
|
|
||||||
status: false,
|
|
||||||
msg: `Table ${key} contains invalid structure.`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: false,
|
|
||||||
msg: 'Parameter data contains invalid table structure.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: false,
|
|
||||||
msg: 'Maximum length for table name could be 32 characters.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return { status: false, msg: 'Table name should be alphanumeric.' }
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
return {
|
||||||
status: false,
|
status: false,
|
||||||
msg: 'First letter of table should be alphabet or underscore.'
|
msg: 'First letter of table should be alphabet or underscore.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!key.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)) {
|
||||||
|
return { status: false, msg: 'Table name should be alphanumeric.' }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.length > 32) {
|
||||||
|
return {
|
||||||
|
status: false,
|
||||||
|
msg: 'Maximum length for table name could be 32 characters.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getType(data[key]) !== 'Array') {
|
||||||
|
return {
|
||||||
|
status: false,
|
||||||
|
msg: 'Parameter data contains invalid table structure.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < data[key].length; i++) {
|
||||||
|
if (this.getType(data[key][i]) !== 'object') {
|
||||||
|
return {
|
||||||
|
status: false,
|
||||||
|
msg: `Table ${key} contains invalid structure.`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { status: true, msg: '' }
|
return { status: true, msg: '' }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user