mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
fix chat
This commit is contained in:
@@ -14,20 +14,20 @@ export class DexieRepository<T> {
|
||||
constructor(table: EntityTable<any, any>, ZodSchema: ZodSchema) {
|
||||
this.table = table as any
|
||||
this.ZodSchema = ZodSchema
|
||||
this.ZodPartialSchema = (ZodSchema as ZodObject<any>).partial() as any;
|
||||
this.ZodPartialSchema = (ZodSchema as ZodObject<any>).partial() as any;
|
||||
}
|
||||
|
||||
async insert(document: T): Promise<RepositoryResult<number, T>> {
|
||||
|
||||
const dataValidation = this.ZodSchema.safeParse(document)
|
||||
|
||||
if(dataValidation.success) {
|
||||
const dataValidation = this.ZodSchema.safeParse(document)
|
||||
|
||||
if(dataValidation.success) {
|
||||
try {
|
||||
const id = await this.table.add(dataValidation.data);
|
||||
return ok(id);
|
||||
} catch (error) {
|
||||
return err(new Error('Failed to insert document: ' + error.message));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return err((dataValidation as unknown as ZodError<T>))
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export class DexieRepository<T> {
|
||||
|
||||
async update(id: any, updatedDocument: Partial<T>) {
|
||||
|
||||
const dataValidation = this.ZodPartialSchema.safeParse(document)
|
||||
const dataValidation = this.ZodPartialSchema.safeParse(updatedDocument)
|
||||
|
||||
if(dataValidation.success) {
|
||||
try {
|
||||
@@ -84,9 +84,10 @@ export class DexieRepository<T> {
|
||||
}
|
||||
}
|
||||
|
||||
async find(filter: Object) {
|
||||
async find(filter: Object): Promise<RepositoryResult<T[], T[]>> {
|
||||
try {
|
||||
const documents = await this.table.where(filter).toArray();
|
||||
const documents: any = await this.table.where(filter).toArray();
|
||||
console.log('documents', {documents})
|
||||
return ok(documents);
|
||||
} catch (error) {
|
||||
return err(new Error('Failed to find documents: ' + error.message));
|
||||
@@ -104,7 +105,8 @@ export class DexieRepository<T> {
|
||||
|
||||
async findAll(): Promise<RepositoryResult<T[], T>> {
|
||||
try {
|
||||
const documents = await this.table.toArray();
|
||||
console.log(this.table)
|
||||
const documents = await this.table.toArray()
|
||||
return ok(documents);
|
||||
} catch (error) {
|
||||
return err(new Error('Failed to retrieve all documents: ' + error.message));
|
||||
|
||||
Reference in New Issue
Block a user