Update mockDb.ts
This commit is contained in:
@@ -140,7 +140,11 @@ export const CondoService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addFamily: async (family: any): Promise<Family> => {
|
addFamily: async (family: any): Promise<Family> => {
|
||||||
const activeId = CondoService.getActiveCondoId();
|
let activeId = CondoService.getActiveCondoId();
|
||||||
|
if (!activeId) {
|
||||||
|
const condos = await CondoService.getCondos();
|
||||||
|
if (condos.length > 0) activeId = condos[0].id;
|
||||||
|
}
|
||||||
return request<Family>('/families', {
|
return request<Family>('/families', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ ...family, condoId: activeId })
|
body: JSON.stringify({ ...family, condoId: activeId })
|
||||||
@@ -209,7 +213,11 @@ export const CondoService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
saveAlert: async (alert: AlertDefinition): Promise<AlertDefinition> => {
|
saveAlert: async (alert: AlertDefinition): Promise<AlertDefinition> => {
|
||||||
const activeId = CondoService.getActiveCondoId();
|
let activeId = CondoService.getActiveCondoId();
|
||||||
|
if (!activeId) {
|
||||||
|
const condos = await CondoService.getCondos();
|
||||||
|
if (condos.length > 0) activeId = condos[0].id;
|
||||||
|
}
|
||||||
if (alert.id) {
|
if (alert.id) {
|
||||||
await request(`/alerts/${alert.id}`, { method: 'PUT', body: JSON.stringify(alert) });
|
await request(`/alerts/${alert.id}`, { method: 'PUT', body: JSON.stringify(alert) });
|
||||||
return alert;
|
return alert;
|
||||||
@@ -267,7 +275,12 @@ export const CondoService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
createTicket: async (data: any): Promise<void> => {
|
createTicket: async (data: any): Promise<void> => {
|
||||||
const activeId = CondoService.getActiveCondoId();
|
let activeId = CondoService.getActiveCondoId();
|
||||||
|
// Robustness: If no activeId (e.g. standard user), fetch condos and use the first one
|
||||||
|
if (!activeId) {
|
||||||
|
const condos = await CondoService.getCondos();
|
||||||
|
if (condos.length > 0) activeId = condos[0].id;
|
||||||
|
}
|
||||||
return request('/tickets', {
|
return request('/tickets', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ ...data, condoId: activeId })
|
body: JSON.stringify({ ...data, condoId: activeId })
|
||||||
@@ -313,7 +326,11 @@ export const CondoService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
createExpense: async (data: any): Promise<void> => {
|
createExpense: async (data: any): Promise<void> => {
|
||||||
const activeId = CondoService.getActiveCondoId();
|
let activeId = CondoService.getActiveCondoId();
|
||||||
|
if (!activeId) {
|
||||||
|
const condos = await CondoService.getCondos();
|
||||||
|
if (condos.length > 0) activeId = condos[0].id;
|
||||||
|
}
|
||||||
if (!activeId) throw new Error("No active condo");
|
if (!activeId) throw new Error("No active condo");
|
||||||
return request('/expenses', {
|
return request('/expenses', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Reference in New Issue
Block a user