Skip to content

Commit

Permalink
Limited the properties to the ones defined in Schema (#7090)
Browse files Browse the repository at this point in the history
* Limited the properties to the ones defined in Schema

* Upped package version
  • Loading branch information
RafaPolit authored Aug 2, 2024
1 parent 4d24191 commit ec919cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
39 changes: 26 additions & 13 deletions app/api/tenants/specs/tenantsModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ describe('tenantsModel', () => {
{
name: 'tenant one',
dbName: 'tenant_one',
indexName: 'index name',
uploadedDocuments: 'path',
attachments: 'path',
customUploads: 'path',
activityLogs: 'path',
stats: 'un-needed data',
healthChecks: 'un-needed data',
},
{
name: 'tenant two',
Expand All @@ -56,21 +63,27 @@ describe('tenantsModel', () => {
});

describe('get()', () => {
it('should return a list of current tenants', async () => {
it('should return a list of current tenants (only properties required for tenant operation)', async () => {
const tenants = await model.get();

expect(tenants).toEqual([
expect.objectContaining({
_id: expect.any(ObjectId),
name: 'tenant one',
dbName: 'tenant_one',
}),
expect.objectContaining({
_id: expect.any(ObjectId),
name: 'tenant two',
dbName: 'tenant_two',
}),
]);
const tenantOne = tenants.find(t => t.name === 'tenant one');
const tenantTwo = tenants.find(t => t.name === 'tenant two');

expect(tenantOne).toEqual({
_id: expect.any(ObjectId),
name: 'tenant one',
dbName: 'tenant_one',
indexName: 'index name',
uploadedDocuments: 'path',
attachments: 'path',
customUploads: 'path',
activityLogs: 'path',
});
expect(tenantTwo).toEqual({
_id: expect.any(ObjectId),
name: 'tenant two',
dbName: 'tenant_two',
});
});
});

Expand Down
11 changes: 6 additions & 5 deletions app/api/tenants/tenantsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const mongoSchema = new mongoose.Schema({
activityLogs: String,
});

export type DBTenant = Partial<Tenant> & { name: string };
export type TenantDocument = Document & DBTenant;
type DBTenant = Partial<Tenant> & { name: string };
type TenantDocument = Document & DBTenant;

export class TenantsModel extends EventEmitter {
class TenantsModel extends EventEmitter {
model?: Model<TenantDocument>;

tenantsDB: mongoose.Connection;
Expand Down Expand Up @@ -96,7 +96,7 @@ export class TenantsModel extends EventEmitter {
'tenants model has not been initialized, make sure you called initialize() method'
);
}
return this.model.find({});
return this.model.find({}, Object.keys(mongoSchema.paths)).lean();
}
}

Expand All @@ -106,4 +106,5 @@ const tenantsModel = async () => {
return model;
};

export { tenantsModel };
export { TenantsModel, tenantsModel };
export type { DBTenant, TenantDocument };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.177.1",
"version": "1.177.2",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"
Expand Down

0 comments on commit ec919cc

Please sign in to comment.