Skip to content

Commit

Permalink
Update features with respect to new osu!droid features
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Nov 25, 2023
1 parent ef75933 commit 145c5dc
Show file tree
Hide file tree
Showing 46 changed files with 948 additions and 652 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alice",
"version": "2023.724.0",
"version": "2023.1125.0",
"description": "A Discord bot for osu!droid.",
"main": "dist/main.js",
"scripts": {
Expand Down
25 changes: 13 additions & 12 deletions src/database/managers/DatabaseCollectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {
UpdateFilter,
UpdateOptions,
UpdateResult,
Document,
} from "mongodb";

/**
* A MongoDB collection manager.
*/
export abstract class DatabaseCollectionManager<
T extends BaseDocument,
C extends Manager
C extends Manager,
> extends Manager {
/**
* The collection that this manager is responsible for.
Expand Down Expand Up @@ -63,12 +64,12 @@ export abstract class DatabaseCollectionManager<
async updateMany(
filter: Filter<T>,
query: UpdateFilter<T> | Partial<T>,
options: UpdateOptions = {}
options: UpdateOptions = {},
): Promise<OperationResult> {
const result: UpdateResult = await this.collection.updateMany(
filter,
query,
options
options,
);

return this.createOperationResult(result.acknowledged);
Expand All @@ -85,12 +86,12 @@ export abstract class DatabaseCollectionManager<
async updateOne(
filter: Filter<T>,
query: UpdateFilter<T> | Partial<T>,
options: UpdateOptions = {}
options: UpdateOptions = {},
): Promise<OperationResult> {
const result: UpdateResult = await this.collection.updateOne(
filter,
query,
options
options,
);

return this.createOperationResult(result.acknowledged);
Expand All @@ -108,7 +109,7 @@ export abstract class DatabaseCollectionManager<
async get<K extends keyof T>(
key: K,
filter: Filter<T> = {},
options?: FindOptions<T>
options?: FindOptions<T>,
): Promise<DiscordCollection<NonNullable<T[K]>, C>> {
if (options?.projection?.[<keyof Document>key] === 0) {
// Prevent cases where key is undefined.
Expand All @@ -129,7 +130,7 @@ export abstract class DatabaseCollectionManager<
for (const data of res) {
collection.set(
<NonNullable<T[K]>>data[key],
new this.utilityInstance(data)
new this.utilityInstance(data),
);
}

Expand All @@ -146,11 +147,11 @@ export abstract class DatabaseCollectionManager<
*/
async getOne(
filter: Filter<T> = {},
options?: FindOptions<T>
options?: FindOptions<T>,
): Promise<C | null> {
const res: T | null = await this.collection.findOne(
filter,
this.processFindOptions(options)
this.processFindOptions(options),
);

return res ? new this.utilityInstance(res) : null;
Expand Down Expand Up @@ -191,8 +192,8 @@ export abstract class DatabaseCollectionManager<
(v) =>
<OptionalUnlessRequiredId<T>>(
Object.assign(this.defaultDocument, v)
)
)
),
),
);

return this.createOperationResult(result.acknowledged);
Expand All @@ -204,7 +205,7 @@ export abstract class DatabaseCollectionManager<
* @param options The options.
*/
protected processFindOptions(
options?: FindOptions<T>
options?: FindOptions<T>,
): FindOptions<T> | undefined {
return options;
}
Expand Down
Loading

0 comments on commit 145c5dc

Please sign in to comment.