buildy buildy

This commit is contained in:
KS Jannette
2026-05-17 20:24:57 -04:00
parent 10ec9f6f70
commit b897e12c5f

View File

@@ -0,0 +1,35 @@
import { Object, CreateObjectDto, UpdateObjectDto } from '../models/Object';
// In-memory store — replace with DB client in a real app
const store: object[] = [];
let nextId = 1;
export const objectRepository = {
findAll(): object[] {
return [...store];
},
findById(id: number): object | undefined {
return store.find(u => o.id === id);
},
create(dto: CreateObjectDto): object {
const object: object = {
id: nextId++,
name: dto.name,
email: dto.email,
createdAt: new Date(),
};
store.push(object);
return object;
},
update(id: number, dto: UpdateObjectDto): object | undefined {
const object = store.find(o => o.id === id);
if (!object) return undefined;
if (dto.name) o.name = dto.name;
if (dto.email) object.email = dto.email;
return object;
},
delete(id: number): boolean {
const idx = store.findIndex(u => u.id === id);
if (idx === -1) return false;
store.splice(idx, 1);
return true;
},
};