refactor: clean up formatting and remove unnecessary line breaks in ProjectAuthorization, OpenAPI, and ModelSchema files

This commit is contained in:
Simon Larsen
2025-06-09 13:50:37 +01:00
parent eb3039f8d7
commit b7ee17fa3e
3 changed files with 27 additions and 29 deletions

View File

@@ -94,9 +94,9 @@ export default class ProjectMiddleware {
props: { isRoot: true },
});
tenantId = apiKeyModel?.projectId || null;
tenantId = apiKeyModel?.projectId || null;
if(!tenantId) {
if (!tenantId) {
throw new BadDataException(
"Project ID not found for the provided API Key.",
);

View File

@@ -532,9 +532,7 @@ export default class OpenAPIUtil {
public static getDefaultApiHeaders(): Array<
ParameterObject | ReferenceObject
> {
return [
];
return [];
}
public static generateUpdateApiSpec(data: {

View File

@@ -35,7 +35,7 @@ export class ModelSchema extends BaseSchema {
* Format permissions array into a human-readable string for OpenAPI documentation
*/
private static formatPermissionsForSchema(
permissions: Array<Permission> | undefined
permissions: Array<Permission> | undefined,
): string {
if (!permissions || permissions.length === 0) {
return "No access - you don't have permission for this operation";
@@ -49,7 +49,7 @@ export class ModelSchema extends BaseSchema {
*/
private static getColumnPermissionsDescription(
model: DatabaseBaseModel,
key: string
key: string,
): string {
const accessControl: ColumnAccessControl | undefined =
model.getColumnAccessControlForAllColumns()[key];
@@ -59,13 +59,13 @@ export class ModelSchema extends BaseSchema {
}
const createPermissions: string = this.formatPermissionsForSchema(
accessControl.create
accessControl.create,
);
const readPermissions: string = this.formatPermissionsForSchema(
accessControl.read
accessControl.read,
);
const updatePermissions: string = this.formatPermissionsForSchema(
accessControl.update
accessControl.update,
);
return `Permissions - Create: [${createPermissions}], Read: [${readPermissions}], Update: [${updatePermissions}]`;
@@ -285,7 +285,7 @@ export class ModelSchema extends BaseSchema {
return ModelSchema.getModelSchema({
modelType: entityArrayType as new () => DatabaseBaseModel,
});
})
}),
)
.openapi({
type: "array",
@@ -348,8 +348,8 @@ export class ModelSchema extends BaseSchema {
`Model schema for ${model.tableName} created with shape: ${JSON.stringify(
shape,
null,
2
)}`
2,
)}`,
);
return schema;
@@ -394,7 +394,7 @@ export class ModelSchema extends BaseSchema {
},
getOperatorSchema: (
operatorType: string,
columnType: TableColumnType
columnType: TableColumnType,
) => {
return this.getOperatorSchema(operatorType, columnType);
},
@@ -408,7 +408,7 @@ export class ModelSchema extends BaseSchema {
}
private static getValidOperatorsForColumnType(
columnType: TableColumnType
columnType: TableColumnType,
): Array<string> {
const commonOperators: Array<string> = [
"EqualTo",
@@ -483,7 +483,7 @@ export class ModelSchema extends BaseSchema {
private static getOperatorSchema(
operatorType: string,
columnType: TableColumnType
columnType: TableColumnType,
): ZodTypes.ZodTypeAny {
const baseValue: ZodTypes.ZodTypeAny =
this.getBaseValueSchemaForColumnType(columnType);
@@ -540,7 +540,7 @@ export class ModelSchema extends BaseSchema {
}
private static getBaseValueSchemaForColumnType(
columnType: TableColumnType
columnType: TableColumnType,
): ZodTypes.ZodTypeAny {
switch (columnType) {
case TableColumnType.ObjectID:
@@ -740,7 +740,7 @@ export class ModelSchema extends BaseSchema {
private static getExampleValueForColumn(
columnType: TableColumnType,
isSecondValue: boolean = false
isSecondValue: boolean = false,
): unknown {
switch (columnType) {
case TableColumnType.ObjectID:
@@ -783,7 +783,7 @@ export class ModelSchema extends BaseSchema {
}
private static getQuerySchemaExample(
modelType: new () => DatabaseBaseModel
modelType: new () => DatabaseBaseModel,
): SchemaExample {
const model: DatabaseBaseModel = new modelType();
const columns: Dictionary<TableColumnMetadata> = getTableColumns(model);
@@ -803,7 +803,7 @@ export class ModelSchema extends BaseSchema {
}
const validOperators: Array<string> = this.getValidOperatorsForColumnType(
column.type
column.type,
);
if (validOperators.length === 0) {
continue;
@@ -870,11 +870,11 @@ export class ModelSchema extends BaseSchema {
}
private static getSelectSchemaExample(
modelType: new () => DatabaseBaseModel
modelType: new () => DatabaseBaseModel,
): SchemaExample {
if (!modelType) {
throw new BadDataException(
"Model type is required to generate select schema example."
"Model type is required to generate select schema example.",
);
}
@@ -919,11 +919,11 @@ export class ModelSchema extends BaseSchema {
}
private static getGroupBySchemaExample(
modelType: new () => DatabaseBaseModel
modelType: new () => DatabaseBaseModel,
): SchemaExample {
if (!modelType) {
throw new BadDataException(
"Model type is required to generate group by schema example."
"Model type is required to generate group by schema example.",
);
}
@@ -1055,7 +1055,7 @@ export class ModelSchema extends BaseSchema {
let zodType: ZodTypes.ZodTypeAny = this.getZodTypeForColumn(
column,
key,
data.schemaType
data.schemaType,
);
// Make fields optional if specified
@@ -1082,8 +1082,8 @@ export class ModelSchema extends BaseSchema {
`${data.schemaType} model schema for ${model.tableName} created with shape: ${JSON.stringify(
shape,
null,
2
)}`
2,
)}`,
);
return schema;
@@ -1093,7 +1093,7 @@ export class ModelSchema extends BaseSchema {
private static getZodTypeForColumn(
column: TableColumnMetadata,
key: string,
schemaType: "create" | "read" | "update" | "delete"
schemaType: "create" | "read" | "update" | "delete",
): ZodTypes.ZodTypeAny {
let zodType: ZodTypes.ZodTypeAny;
@@ -1294,7 +1294,7 @@ export class ModelSchema extends BaseSchema {
return schemaMethod({
modelType: entityArrayType as new () => DatabaseBaseModel,
});
})
}),
)
.openapi({
type: "array",