feat: Enhance condo and family data models
Adds new fields for detailed address information and notes to the Condo and Family types. Updates database schema and server API endpoints to support these new fields, improving data richness for location and specific family/condo details.
This commit is contained in:
@@ -92,7 +92,8 @@ export const CondoService = {
|
||||
|
||||
getNotices: async (condoId?: string): Promise<Notice[]> => {
|
||||
let url = '/notices';
|
||||
if (condoId) url += `?condoId=${condoId}`;
|
||||
const activeId = condoId || CondoService.getActiveCondoId();
|
||||
if (activeId) url += `?condoId=${activeId}`;
|
||||
return request<Notice[]>(url);
|
||||
},
|
||||
|
||||
@@ -142,11 +143,8 @@ export const CondoService = {
|
||||
|
||||
// Set active condo if user belongs to a family
|
||||
if (data.user.familyId) {
|
||||
// We need to fetch family to get condoId.
|
||||
// For simplicity, we trust the flow or fetch families next.
|
||||
// In a real app, login might return condoId directly.
|
||||
try {
|
||||
const families = await CondoService.getFamilies(); // This will filter by user perms
|
||||
const families = await CondoService.getFamilies(); // This will filter by user perms automatically on server
|
||||
const fam = families.find(f => f.id === data.user.familyId);
|
||||
if (fam) {
|
||||
localStorage.setItem(STORAGE_KEYS.ACTIVE_CONDO_ID, fam.condoId);
|
||||
@@ -194,13 +192,11 @@ export const CondoService = {
|
||||
|
||||
// --- FAMILIES ---
|
||||
|
||||
getFamilies: async (): Promise<Family[]> => {
|
||||
const activeCondoId = CondoService.getActiveCondoId();
|
||||
// Pass condoId to filter on server if needed, or filter client side.
|
||||
// The server `getFamilies` endpoint handles filtering based on user role.
|
||||
// However, if we are admin, we want ALL families, but usually filtered by the UI for the active condo.
|
||||
// Let's get all allowed families from server.
|
||||
return request<Family[]>('/families');
|
||||
getFamilies: async (condoId?: string): Promise<Family[]> => {
|
||||
let url = '/families';
|
||||
const activeId = condoId || CondoService.getActiveCondoId();
|
||||
if (activeId) url += `?condoId=${activeId}`;
|
||||
return request<Family[]>(url);
|
||||
},
|
||||
|
||||
addFamily: async (familyData: Omit<Family, 'id' | 'balance' | 'condoId'>): Promise<Family> => {
|
||||
@@ -239,8 +235,11 @@ export const CondoService = {
|
||||
|
||||
// --- USERS ---
|
||||
|
||||
getUsers: async (): Promise<User[]> => {
|
||||
return request<User[]>('/users');
|
||||
getUsers: async (condoId?: string): Promise<User[]> => {
|
||||
let url = '/users';
|
||||
const activeId = condoId || CondoService.getActiveCondoId();
|
||||
if (activeId) url += `?condoId=${activeId}`;
|
||||
return request<User[]>(url);
|
||||
},
|
||||
|
||||
createUser: async (userData: any) => {
|
||||
@@ -263,15 +262,19 @@ export const CondoService = {
|
||||
|
||||
// --- ALERTS ---
|
||||
|
||||
getAlerts: async (): Promise<AlertDefinition[]> => {
|
||||
return request<AlertDefinition[]>('/alerts');
|
||||
getAlerts: async (condoId?: string): Promise<AlertDefinition[]> => {
|
||||
let url = '/alerts';
|
||||
const activeId = condoId || CondoService.getActiveCondoId();
|
||||
if (activeId) url += `?condoId=${activeId}`;
|
||||
return request<AlertDefinition[]>(url);
|
||||
},
|
||||
|
||||
saveAlert: async (alert: AlertDefinition): Promise<AlertDefinition> => {
|
||||
saveAlert: async (alert: AlertDefinition & { condoId?: string }): Promise<AlertDefinition> => {
|
||||
const activeCondoId = CondoService.getActiveCondoId();
|
||||
if (!alert.id) {
|
||||
return request<AlertDefinition>('/alerts', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(alert)
|
||||
body: JSON.stringify({ ...alert, condoId: activeCondoId })
|
||||
});
|
||||
} else {
|
||||
return request<AlertDefinition>(`/alerts/${alert.id}`, {
|
||||
|
||||
Reference in New Issue
Block a user