|
|
|
@ -1,6 +1,20 @@ |
|
|
|
|
import type { Contact, ImportSource } from '@/types/contact'; |
|
|
|
|
import type { Group } from '@/types/group'; |
|
|
|
|
|
|
|
|
|
// Raw data types from JSON files (with string dates)
|
|
|
|
|
interface RawContact extends Omit<Contact, 'createdAt' | 'updatedAt' | 'joinedAt' | 'invitedAt'> { |
|
|
|
|
createdAt: string; |
|
|
|
|
updatedAt: string; |
|
|
|
|
joinedAt?: string; |
|
|
|
|
invitedAt?: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface RawGroup extends Omit<Group, 'createdAt' | 'updatedAt' | 'latestPostAt'> { |
|
|
|
|
createdAt: string; |
|
|
|
|
updatedAt: string; |
|
|
|
|
latestPostAt?: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const dataService = { |
|
|
|
|
async getContacts(): Promise<Contact[]> { |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
@ -8,7 +22,7 @@ export const dataService = { |
|
|
|
|
try { |
|
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
|
const contactsData = await response.json(); |
|
|
|
|
const contacts = contactsData.map((contact: any) => { |
|
|
|
|
const contacts = contactsData.map((contact: RawContact) => { |
|
|
|
|
const processedContact: Contact = { |
|
|
|
|
...contact, |
|
|
|
|
createdAt: new Date(contact.createdAt), |
|
|
|
@ -111,7 +125,7 @@ export const dataService = { |
|
|
|
|
try { |
|
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
|
const groupsData = await response.json(); |
|
|
|
|
const groups = groupsData.map((group: any) => { |
|
|
|
|
const groups = groupsData.map((group: RawGroup) => { |
|
|
|
|
const processedGroup: Group = { |
|
|
|
|
...group, |
|
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
@ -172,8 +186,8 @@ export const dataService = { |
|
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
|
const groupsData = await response.json(); |
|
|
|
|
const userGroups = groupsData |
|
|
|
|
.filter((group: Record<string, unknown>) => (group.memberIds as string[]).includes(userId)) |
|
|
|
|
.map((group: any) => { |
|
|
|
|
.filter((group: RawGroup) => group.memberIds.includes(userId)) |
|
|
|
|
.map((group: RawGroup) => { |
|
|
|
|
const processedGroup: Group = { |
|
|
|
|
...group, |
|
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
|