Skip to content

Commit

Permalink
fix(database): array type not extracted properly (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Vol committed Jun 2, 2022
1 parent 6cf7070 commit 7cb2546
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
21 changes: 19 additions & 2 deletions modules/database/src/adapters/mongoose-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,25 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
},
cms: {
authentication: false,
crudOperations: false,
enabled: false,
crudOperations: {
create: {
enabled: false,
authenticated: false,
},
read: {
enabled: false,
authenticated: false,
},
update: {
enabled: false,
authenticated: false,
},
delete: {
enabled: false,
authenticated: false,
},
},
enabled: true,
},
},
};
Expand Down
21 changes: 19 additions & 2 deletions modules/database/src/adapters/sequelize-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,25 @@ export class SequelizeAdapter extends DatabaseAdapter<SequelizeSchema> {
},
cms: {
authentication: false,
crudOperations: false,
enabled: false,
crudOperations: {
create: {
enabled: false,
authenticated: false,
},
read: {
enabled: false,
authenticated: false,
},
update: {
enabled: false,
authenticated: false,
},
delete: {
enabled: false,
authenticated: false,
},
},
enabled: true,
},
},
});
Expand Down
22 changes: 17 additions & 5 deletions modules/database/src/introspection/mongoose/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ConduitModel, ConduitModelField } from '@conduitplatform/grpc-sdk';
import {
ConduitModel,
ConduitModelField,
Indexable,
TYPE,
} from '@conduitplatform/grpc-sdk';

export const INITIAL_DB_SCHEMAS = [
'_declaredschemas',
Expand All @@ -18,17 +23,24 @@ export function mongoSchemaConverter(mongoSchema: any): ConduitModel {
return conduitSchema as ConduitModel;
}

function extractType(field: any): ConduitModelField {
function extractType(field: Indexable) {
let conduitField: Partial<ConduitModelField> = {};
if (Array.isArray(field.type)) {
conduitField.type = field.type.filter(
(t: string) => t !== 'Undefined' && t !== 'Null'
)[0];
} else if (
(field.type === 'Array' || field.name === 'Array') &&
field.hasOwnProperty('types')
) {
let nestedField = field.types[0];
nestedField = extractType(nestedField.types[0]);
return [nestedField];
} else {
conduitField.type = field.type;
conduitField.type = field.type ?? field.name;
}
if(conduitField.type === 'Document') {
conduitField.type = 'Object' as any; //workaround for Document types
if (conduitField.type === 'Document') {
conduitField.type = TYPE.JSON; //workaround for Document types
}
return conduitField;
}

0 comments on commit 7cb2546

Please sign in to comment.