mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
change creat to createOrUpdate
This commit is contained in:
+33
-12
@@ -24,20 +24,13 @@ export const roomDataSource = new Dexie('FriendDatabase') as Dexie & {
|
||||
room: EntityTable<TableRoom, 'id'>;
|
||||
};
|
||||
|
||||
|
||||
|
||||
roomDataSource.version(1).stores({
|
||||
room: '++id, createdBy, roomName, roomType, expirationDate'
|
||||
room: 'id, createdBy, roomName, roomType, expirationDate'
|
||||
});
|
||||
|
||||
|
||||
interface CreateRoomParams {
|
||||
id?: string;
|
||||
roomName?: string;
|
||||
createdBy?: any;
|
||||
createdAt?: Date;
|
||||
expirationDate?: Date;
|
||||
roomType?: any;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -48,14 +41,42 @@ export class RoomLocalDataSourceService {
|
||||
constructor() {}
|
||||
|
||||
|
||||
async createRoom(data: CreateRoomParams) {
|
||||
|
||||
async createRoom(data: TableRoom) {
|
||||
try {
|
||||
const result = await roomDataSource.room.add(data)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
}
|
||||
|
||||
async updateRoom(data: TableRoom) {
|
||||
try {
|
||||
const result = await roomDataSource.room.update(data.id, data);
|
||||
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
}
|
||||
|
||||
async createOrUpdateRoom(data: TableRoom) {
|
||||
const createResult = await this.createRoom(data)
|
||||
|
||||
if(createResult.isOk()) {
|
||||
return this.updateRoom(data)
|
||||
} else {
|
||||
return createResult
|
||||
}
|
||||
}
|
||||
|
||||
async getRoomById(id: any) {
|
||||
try {
|
||||
const result = await roomDataSource.room.get(id)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user