|
|
|
@ -23,20 +23,15 @@ export const dataService = { |
|
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
|
const contactsData = await response.json(); |
|
|
|
|
const contacts = contactsData.map((contact: RawContact) => { |
|
|
|
|
const { createdAt, updatedAt, joinedAt, invitedAt, ...contactData } = contact; |
|
|
|
|
const processedContact: Contact = { |
|
|
|
|
...contact, |
|
|
|
|
createdAt: new Date(contact.createdAt), |
|
|
|
|
updatedAt: new Date(contact.updatedAt) |
|
|
|
|
...contactData, |
|
|
|
|
createdAt: new Date(createdAt), |
|
|
|
|
updatedAt: new Date(updatedAt), |
|
|
|
|
joinedAt: joinedAt ? new Date(joinedAt) : undefined, |
|
|
|
|
invitedAt: invitedAt ? new Date(invitedAt) : undefined |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Convert optional date fields if they exist
|
|
|
|
|
if (contact.joinedAt) { |
|
|
|
|
processedContact.joinedAt = new Date(contact.joinedAt); |
|
|
|
|
} |
|
|
|
|
if (contact.invitedAt) { |
|
|
|
|
processedContact.invitedAt = new Date(contact.invitedAt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return processedContact; |
|
|
|
|
}); |
|
|
|
|
resolve(contacts); |
|
|
|
@ -126,17 +121,14 @@ export const dataService = { |
|
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
|
const groupsData = await response.json(); |
|
|
|
|
const groups = groupsData.map((group: RawGroup) => { |
|
|
|
|
const { createdAt, updatedAt, latestPostAt, ...groupData } = group; |
|
|
|
|
const processedGroup: Group = { |
|
|
|
|
...group, |
|
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
|
updatedAt: new Date(group.updatedAt) |
|
|
|
|
...groupData, |
|
|
|
|
createdAt: new Date(createdAt), |
|
|
|
|
updatedAt: new Date(updatedAt), |
|
|
|
|
latestPostAt: latestPostAt ? new Date(latestPostAt) : undefined |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Convert optional date fields if they exist
|
|
|
|
|
if (group.latestPostAt) { |
|
|
|
|
processedGroup.latestPostAt = new Date(group.latestPostAt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return processedGroup; |
|
|
|
|
}); |
|
|
|
|
resolve(groups); |
|
|
|
@ -188,17 +180,14 @@ export const dataService = { |
|
|
|
|
const userGroups = groupsData |
|
|
|
|
.filter((group: RawGroup) => group.memberIds.includes(userId)) |
|
|
|
|
.map((group: RawGroup) => { |
|
|
|
|
const { createdAt, updatedAt, latestPostAt, ...groupData } = group; |
|
|
|
|
const processedGroup: Group = { |
|
|
|
|
...group, |
|
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
|
updatedAt: new Date(group.updatedAt) |
|
|
|
|
...groupData, |
|
|
|
|
createdAt: new Date(createdAt), |
|
|
|
|
updatedAt: new Date(updatedAt), |
|
|
|
|
latestPostAt: latestPostAt ? new Date(latestPostAt) : undefined |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Convert optional date fields if they exist
|
|
|
|
|
if (group.latestPostAt) { |
|
|
|
|
processedGroup.latestPostAt = new Date(group.latestPostAt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return processedGroup; |
|
|
|
|
}); |
|
|
|
|
resolve(userGroups); |
|
|
|
|