Skip to content

Commit

Permalink
Merge pull request #304 from Josuto/update_mongoose
Browse files Browse the repository at this point in the history
chore: update Mongoose dependency
  • Loading branch information
Josuto authored Oct 20, 2024
2 parents 11fd804 + c60ab4a commit ad009af
Show file tree
Hide file tree
Showing 4 changed files with 2,046 additions and 1,919 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monguito",
"version": "6.0.1",
"version": "6.0.2",
"description": "MongoDB Abstract Repository implementation for Node.js",
"author": "Josu Martinez <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -88,9 +88,9 @@
"lint-staged": "^15.2.10",
"microbundle": "^0.15.1",
"mongodb-memory-server": "^10.1.2",
"mongoose": "^8.4.1",
"mongoose": "^8.7.2",
"mongoose-unique-validator": "^5.0.0",
"prettier": "^3.3.3",
"prettier": "^3.3.2",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
Expand Down
2 changes: 1 addition & 1 deletion src/mongoose.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export abstract class MongooseRepository<T extends Entity & UpdateQuery<T>>
document.isNew = false;
if (isAuditable(document)) {
if (userId) document.$locals.userId = userId;
document.__v = (document.__v ?? 0) + 1;
document.__v = ((document.__v as number) ?? 0) + 1;
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/util/mongo-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ export const insert = async (
entity['__t'] = discriminatorKey;
}

return mongoose.connection.db
.collection(collection)
return mongoose.connection
.db!.collection(collection)
.insertOne(entity)
.then((result) => result.insertedId.toString());
};

export const findOne = async (filter: any, collection: string) => {
return await mongoose.connection.db.collection(collection).findOne(filter);
return await mongoose.connection.db!.collection(collection).findOne(filter);
};

export const findById = async (id: string, collection: string) => {
return await mongoose.connection.db.collection(collection).findOne({ id });
return await mongoose.connection.db!.collection(collection).findOne({ id });
};

export const deleteAll = async (collection: string) => {
await mongoose.connection.db.collection(collection).deleteMany({});
await mongoose.connection.db!.collection(collection).deleteMany({});
};

export const closeMongoConnection = async () => {
Expand Down
Loading

0 comments on commit ad009af

Please sign in to comment.