buildah buildah buildah
This commit is contained in:
@@ -1,31 +1,41 @@
|
||||
import { Object, CreateObjectDto, UpdateObjectDto } from '../models/Object';
|
||||
import {
|
||||
Object as StoredObject,
|
||||
CreateObjectDto,
|
||||
UpdateObjectDto,
|
||||
} from '../models/Object';
|
||||
|
||||
// In-memory store — replace with DB client in a real app
|
||||
const store: object[] = [];
|
||||
const store: StoredObject[] = [];
|
||||
let nextId = 1;
|
||||
|
||||
export const objectRepository = {
|
||||
findAll(): object[] {
|
||||
findAll(): StoredObject[] {
|
||||
return [...store];
|
||||
},
|
||||
findById(id: number): object | undefined {
|
||||
return store.find(u => o.id === id);
|
||||
|
||||
findById(id: number): StoredObject | undefined {
|
||||
return store.find(u => u.id === id);
|
||||
},
|
||||
create(dto: CreateObjectDto): object {
|
||||
const object: object = {
|
||||
|
||||
create(dto: CreateObjectDto): StoredObject {
|
||||
const row: StoredObject = {
|
||||
id: nextId++,
|
||||
name: dto.name,
|
||||
email: dto.email,
|
||||
createdAt: new Date(),
|
||||
};
|
||||
store.push(object);
|
||||
return object;
|
||||
store.push(row);
|
||||
return row;
|
||||
},
|
||||
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;
|
||||
|
||||
update(id: number, dto: UpdateObjectDto): StoredObject | undefined {
|
||||
const row = store.find(o => o.id === id);
|
||||
if (!row) return undefined;
|
||||
if (dto.name !== undefined) row.name = dto.name;
|
||||
if (dto.email !== undefined) row.email = dto.email;
|
||||
return row;
|
||||
},
|
||||
|
||||
delete(id: number): boolean {
|
||||
const idx = store.findIndex(u => u.id === id);
|
||||
if (idx === -1) return false;
|
||||
|
||||
Reference in New Issue
Block a user