|
|
@ -3,12 +3,12 @@ import type { Group } from '@/types/group'; |
|
|
|
|
|
|
|
|
|
|
|
export const dataService = { |
|
|
|
export const dataService = { |
|
|
|
async getContacts(): Promise<Contact[]> { |
|
|
|
async getContacts(): Promise<Contact[]> { |
|
|
|
return new Promise(async (resolve) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
const contactsData = await response.json(); |
|
|
|
const contactsData = await response.json(); |
|
|
|
const contacts = contactsData.map((contact: any) => { |
|
|
|
const contacts = contactsData.map((contact: Contact & { createdAt: string; updatedAt: string; joinedAt?: string; invitedAt?: string; }) => { |
|
|
|
const processedContact = { |
|
|
|
const processedContact = { |
|
|
|
...contact, |
|
|
|
...contact, |
|
|
|
createdAt: new Date(contact.createdAt), |
|
|
|
createdAt: new Date(contact.createdAt), |
|
|
@ -35,12 +35,12 @@ export const dataService = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async getContact(id: string): Promise<Contact | undefined> { |
|
|
|
async getContact(id: string): Promise<Contact | undefined> { |
|
|
|
return new Promise(async (resolve) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
const contactsData = await response.json(); |
|
|
|
const contactsData = await response.json(); |
|
|
|
const contact = contactsData.find((c: any) => c.id === id); |
|
|
|
const contact = contactsData.find((c: Contact) => c.id === id); |
|
|
|
if (contact) { |
|
|
|
if (contact) { |
|
|
|
const processedContact = { |
|
|
|
const processedContact = { |
|
|
|
...contact, |
|
|
|
...contact, |
|
|
@ -69,7 +69,7 @@ export const dataService = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async getImportSources(): Promise<ImportSource[]> { |
|
|
|
async getImportSources(): Promise<ImportSource[]> { |
|
|
|
return new Promise(async (resolve) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch('/import-sources.json'); |
|
|
|
const response = await fetch('/import-sources.json'); |
|
|
@ -84,14 +84,14 @@ export const dataService = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async importFromSource(sourceId: string): Promise<Contact[]> { |
|
|
|
async importFromSource(sourceId: string): Promise<Contact[]> { |
|
|
|
return new Promise(async (resolve) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
const response = await fetch('/contacts.json'); |
|
|
|
const contactsData = await response.json(); |
|
|
|
const contactsData = await response.json(); |
|
|
|
const filteredContacts = contactsData |
|
|
|
const filteredContacts = contactsData |
|
|
|
.filter((contact: any) => contact.source === sourceId) |
|
|
|
.filter((contact: Contact) => contact.source === sourceId) |
|
|
|
.map((contact: any) => ({ |
|
|
|
.map((contact: Contact) => ({ |
|
|
|
...contact, |
|
|
|
...contact, |
|
|
|
createdAt: new Date(contact.createdAt), |
|
|
|
createdAt: new Date(contact.createdAt), |
|
|
|
updatedAt: new Date(contact.updatedAt) |
|
|
|
updatedAt: new Date(contact.updatedAt) |
|
|
@ -106,14 +106,14 @@ export const dataService = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async getGroups(): Promise<Group[]> { |
|
|
|
async getGroups(): Promise<Group[]> { |
|
|
|
return new Promise(async (resolve) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
const groupsData = await response.json(); |
|
|
|
const groupsData = await response.json(); |
|
|
|
const groups = groupsData.map((group: any) => { |
|
|
|
const groups = groupsData.map((group: Group & { createdAt: string; updatedAt: string; latestPostAt?: string; }) => { |
|
|
|
const processedGroup = { |
|
|
|
const processedGroup = { |
|
|
|
...group, |
|
|
|
...(group as unknown as Group), |
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
updatedAt: new Date(group.updatedAt) |
|
|
|
updatedAt: new Date(group.updatedAt) |
|
|
|
}; |
|
|
|
}; |
|
|
@ -135,15 +135,15 @@ export const dataService = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async getGroup(id: string): Promise<Group | undefined> { |
|
|
|
async getGroup(id: string): Promise<Group | undefined> { |
|
|
|
return new Promise(async (resolve) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
const groupsData = await response.json(); |
|
|
|
const groupsData = await response.json(); |
|
|
|
const group = groupsData.find((g: any) => g.id === id); |
|
|
|
const group = groupsData.find((g: Group) => g.id === id); |
|
|
|
if (group) { |
|
|
|
if (group) { |
|
|
|
const processedGroup = { |
|
|
|
const processedGroup = { |
|
|
|
...group, |
|
|
|
...(group as unknown as Group), |
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
updatedAt: new Date(group.updatedAt) |
|
|
|
updatedAt: new Date(group.updatedAt) |
|
|
|
}; |
|
|
|
}; |
|
|
@ -166,23 +166,23 @@ export const dataService = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async getGroupsForUser(userId: string): Promise<Group[]> { |
|
|
|
async getGroupsForUser(userId: string): Promise<Group[]> { |
|
|
|
return new Promise(async (resolve) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
const response = await fetch('/groups.json'); |
|
|
|
const groupsData = await response.json(); |
|
|
|
const groupsData = await response.json(); |
|
|
|
const userGroups = groupsData |
|
|
|
const userGroups = groupsData |
|
|
|
.filter((group: any) => group.memberIds.includes(userId)) |
|
|
|
.filter((group: Record<string, unknown>) => (group.memberIds as string[]).includes(userId)) |
|
|
|
.map((group: any) => { |
|
|
|
.map((group: Record<string, unknown>) => { |
|
|
|
const processedGroup = { |
|
|
|
const processedGroup: Group = { |
|
|
|
...group, |
|
|
|
...(group as unknown as Group), |
|
|
|
createdAt: new Date(group.createdAt), |
|
|
|
createdAt: new Date(group.createdAt as string), |
|
|
|
updatedAt: new Date(group.updatedAt) |
|
|
|
updatedAt: new Date(group.updatedAt as string) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Convert optional date fields if they exist
|
|
|
|
// Convert optional date fields if they exist
|
|
|
|
if (group.latestPostAt) { |
|
|
|
if (group.latestPostAt) { |
|
|
|
processedGroup.latestPostAt = new Date(group.latestPostAt); |
|
|
|
processedGroup.latestPostAt = new Date(group.latestPostAt as string); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return processedGroup; |
|
|
|
return processedGroup; |
|
|
|