set member to admin

This commit is contained in:
Peter Maquiran
2024-08-06 11:24:00 +01:00
parent 7e14f55383
commit 2f214e0025
3889 changed files with 581 additions and 1962886 deletions
@@ -0,0 +1,94 @@
import { Result, ok, err, ResultAsync } from 'neverthrow';
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
// Define a type for the Result of repository operations
type RepositoryResult<T> = Result<T, Error>;
export class DexieRepository<ISchema, T> {
private table: EntityTable<ISchema, any>;
constructor(table: EntityTable<any, any>) {
this.table = table as any
}
async insert(document: T): Promise<RepositoryResult<number>> {
try {
const id = await this.table.add(document as any);
return ok(id);
} catch (error) {
return err(new Error('Failed to insert document: ' + error.message));
}
}
async insertMany(documents: T[]): Promise<RepositoryResult<number[]>> {
try {
const ids = await this.table.bulkAdd(documents as any);
return ok(ids);
} catch (error) {
return err(new Error('Failed to insert multiple documents: ' + error.message));
}
}
async update(id: any, updatedDocument: Partial<T>) {
try {
const updatedCount = await this.table.update(id, updatedDocument as any);
return ok(updatedCount);
} catch (error) {
return err(new Error('Failed to update document: ' + error.message));
}
}
async delete(id: any): Promise<RepositoryResult<void>> {
try {
await this.table.delete(id);
return ok(undefined);
} catch (error) {
return err(new Error('Failed to delete document: ' + error.message));
}
}
async findById(id: any) {
try {
const document = await this.table.get(id);
return ok(document);
} catch (error) {
return err(new Error('Failed to find document by ID: ' + error.message));
}
}
// async find(filter: any) {
// try {
// const documents = await this.table.where(filter).toArray();
// return ok(documents);
// } catch (error) {
// return err(new Error('Failed to find documents: ' + error.message));
// }
// }
// async findOne(filter: any): Promise<RepositoryResult<T | undefined>> {
// try {
// const document = await this.table.where(filter).first();
// return ok(document);
// } catch (error) {
// return err(new Error('Failed to find document: ' + error.message));
// }
// }
// async findAll(): Promise<RepositoryResult<T[]>> {
// try {
// const documents = await this.table.toArray();
// return ok(documents);
// } catch (error) {
// return err(new Error('Failed to retrieve all documents: ' + error.message));
// }
// }
// async count(filter?: any): Promise<RepositoryResult<number>> {
// try {
// const count = filter ? await this.table.where(filter).count() : await this.table.count();
// return ok(count);
// } catch (error) {
// return err(new Error('Failed to count documents: ' + error.message));
// }
// }
}