1
0
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:
2021-06-11 22:53:06 +05:00
parent 06ebb52bc9
commit ccb4ec6e03

View File

@@ -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,16 +607,37 @@ 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_]*$/)) { return {
if (key.length <= 32) { status: false,
if (this.getType(data[key]) === 'Array') { 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++) { for (let i = 0; i < data[key].length; i++) {
if (this.getType(data[key][i]) !== 'object') { if (this.getType(data[key][i]) !== 'object') {
return { return {
@@ -624,27 +646,6 @@ export default class SASjs {
} }
} }
} }
} 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 {
status: false,
msg: 'First letter of table should be alphabet or underscore.'
}
}
} }
return { status: true, msg: '' } return { status: true, msg: '' }
} }