Skip to content

Commit f2d2529

Browse files
Updated queries to remove jobSources relation.
1 parent 16217b0 commit f2d2529

File tree

8 files changed

+56
-86
lines changed

8 files changed

+56
-86
lines changed

src/app/api/jobs/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const GET = withLogging(async (request: NextRequest) => {
2323
company: true,
2424
tags: { include: { tag: true } },
2525
metadata: true,
26-
sources: true,
2726
},
2827
})
2928

src/app/jobs/[id]/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type JobWithRelations = Prisma.JobGetPayload<{
1111
company: true
1212
tags: { include: { tag: true } }
1313
metadata: true
14-
sources: true
1514
}
1615
}>
1716

@@ -33,7 +32,6 @@ export default async function JobPage({ params }: JobPageProps) {
3332
company: true,
3433
tags: { include: { tag: true } },
3534
metadata: true,
36-
sources: true,
3735
},
3836
})) as JobWithRelations | null
3937

src/app/jobs/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type JobWithRelations = Prisma.JobGetPayload<{
1010
company: true
1111
tags: { include: { tag: true } }
1212
metadata: true
13-
sources: true
1413
}
1514
}>
1615

@@ -28,7 +27,6 @@ export default async function Home(props: { searchParams: Promise<{ page?: strin
2827
company: true,
2928
tags: { include: { tag: true } },
3029
metadata: true,
31-
sources: true,
3230
},
3331
})) as JobWithRelations[]
3432

src/components/jobs/JobDetails.tsx

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type JobWithRelations = Prisma.JobGetPayload<{
1010
company: true
1111
tags: { include: { tag: true } }
1212
metadata: true
13-
sources: true
1413
}
1514
}>
1615

@@ -25,8 +24,7 @@ const JobDetails: React.FC<JobDetailsProps> = ({ job }) => {
2524
}
2625

2726
const getSourceName = () => {
28-
const source = job.sources[0]
29-
return source ? source.source : 'unknown'
27+
return job.source || 'unknown'
3028
}
3129

3230
const formatDate = (date: Date) => {
@@ -162,6 +160,49 @@ const JobDetails: React.FC<JobDetailsProps> = ({ job }) => {
162160
</div>
163161
)}
164162

163+
{/* Source Details */}
164+
<div className="mb-6">
165+
<h3 className="text-lg font-semibold text-gray-800 mb-3">Source Details</h3>
166+
<div className="space-y-4">
167+
<div className="bg-gray-50 p-4 rounded-lg">
168+
<div className="flex justify-between items-start mb-2">
169+
<div>
170+
<h4 className="font-medium text-gray-800">Source: {job.source || 'unknown'}</h4>
171+
{job.externalId && (
172+
<p className="text-sm text-gray-600">External ID: {job.externalId}</p>
173+
)}
174+
</div>
175+
<span className="text-xs text-gray-500">{formatDate(job.createdAt)}</span>
176+
</div>
177+
178+
{job.url && (
179+
<div className="mb-2">
180+
<span className="text-sm font-medium text-gray-600">URL: </span>
181+
<Link
182+
href={job.url}
183+
target="_blank"
184+
rel="noopener noreferrer"
185+
className="text-blue-600 hover:text-blue-800 text-sm break-all"
186+
>
187+
{job.url}
188+
</Link>
189+
</div>
190+
)}
191+
192+
{job.data && (
193+
<details className="mt-2">
194+
<summary className="cursor-pointer text-sm font-medium text-gray-600 hover:text-gray-800">
195+
Raw Data
196+
</summary>
197+
<pre className="mt-2 text-xs bg-gray-100 p-3 rounded overflow-x-auto">
198+
{formatJsonData(job.data)}
199+
</pre>
200+
</details>
201+
)}
202+
</div>
203+
</div>
204+
</div>
205+
165206
{/* Metadata */}
166207
{job.metadata.length > 0 && (
167208
<div className="mb-6">
@@ -184,53 +225,6 @@ const JobDetails: React.FC<JobDetailsProps> = ({ job }) => {
184225
</div>
185226
)}
186227

187-
{/* Sources */}
188-
<div className="mb-6">
189-
<h3 className="text-lg font-semibold text-gray-800 mb-3">Sources</h3>
190-
<div className="space-y-4">
191-
{job.sources.map((source, index) => (
192-
<div key={source.id} className="bg-gray-50 p-4 rounded-lg">
193-
<div className="flex justify-between items-start mb-2">
194-
<div>
195-
<h4 className="font-medium text-gray-800">
196-
Source {index + 1}: {source.source}
197-
</h4>
198-
{source.externalId && (
199-
<p className="text-sm text-gray-600">External ID: {source.externalId}</p>
200-
)}
201-
</div>
202-
<span className="text-xs text-gray-500">{formatDate(source.createdAt)}</span>
203-
</div>
204-
205-
{source.rawUrl && (
206-
<div className="mb-2">
207-
<span className="text-sm font-medium text-gray-600">Raw URL: </span>
208-
<Link
209-
href={source.rawUrl}
210-
target="_blank"
211-
rel="noopener noreferrer"
212-
className="text-blue-600 hover:text-blue-800 text-sm break-all"
213-
>
214-
{source.rawUrl}
215-
</Link>
216-
</div>
217-
)}
218-
219-
{source.data && (
220-
<details className="mt-2">
221-
<summary className="cursor-pointer text-sm font-medium text-gray-600 hover:text-gray-800">
222-
Raw Data
223-
</summary>
224-
<pre className="mt-2 text-xs bg-gray-100 p-3 rounded overflow-x-auto">
225-
{formatJsonData(source.data)}
226-
</pre>
227-
</details>
228-
)}
229-
</div>
230-
))}
231-
</div>
232-
</div>
233-
234228
{/* Actions */}
235229
<div className="flex flex-wrap gap-4 pt-6 border-t border-gray-200">
236230
<Link

src/components/jobs/JobsTable.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type JobWithRelations = Prisma.JobGetPayload<{
1313
company: true
1414
tags: { include: { tag: true } }
1515
metadata: true
16-
sources: true
1716
}
1817
}>
1918

@@ -33,8 +32,7 @@ const JobsTable: React.FC<Props> = ({ jobs, totalJobs, jobsPerPage, currentPage
3332
}
3433

3534
const getSourceName = (job: JobWithRelations) => {
36-
const source = job.sources[0] // Get the first source
37-
return source ? source.source : 'unknown'
35+
return job.source || 'unknown'
3836
}
3937

4038
const formatDate = (date: Date) => {

src/lib/jobs/jobs.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ export type JobInput = {
1212
url: string
1313
postedAt?: Date | string
1414
description?: string
15-
isRemote?: boolean
15+
isRemote?: boolean | null
1616
tags?: string[]
1717
metadata?: Record<string, string>
1818
source: {
1919
name: string
2020
externalId?: string
21-
rawUrl?: string
2221
data?: any
2322
}
2423
}
@@ -46,7 +45,11 @@ export async function upsertJob(input: JobInput) {
4645
location: input.location,
4746
postedAt: input.postedAt ? new Date(input.postedAt) : undefined,
4847
description: input.description,
49-
isRemote: input.isRemote,
48+
isRemote: input.isRemote ?? undefined,
49+
// Write source-related fields directly on Job
50+
source: input.source?.name,
51+
externalId: input.source?.externalId,
52+
data: input.source?.data as any,
5053
company: companyRecord ? { connect: { id: companyRecord.id } } : undefined,
5154
updatedAt: new Date(),
5255
},
@@ -56,8 +59,12 @@ export async function upsertJob(input: JobInput) {
5659
location: input.location,
5760
postedAt: input.postedAt ? new Date(input.postedAt) : undefined,
5861
description: input.description,
59-
isRemote: input.isRemote,
62+
isRemote: input.isRemote ?? undefined,
6063
url: input.url,
64+
// Write source-related fields directly on Job
65+
source: input.source?.name,
66+
externalId: input.source?.externalId,
67+
data: input.source?.data as any,
6168
company: companyRecord ? { connect: { id: companyRecord.id } } : undefined,
6269
},
6370
})
@@ -90,27 +97,5 @@ export async function upsertJob(input: JobInput) {
9097
}
9198
}
9299

93-
// Upsert job source (also requires a compound unique constraint for source + externalId)
94-
await prisma.jobSource.upsert({
95-
where: {
96-
source_externalId: {
97-
source: input.source.name,
98-
externalId: input.source.externalId || '',
99-
},
100-
},
101-
update: {
102-
rawUrl: input.source.rawUrl,
103-
data: input.source.data,
104-
jobId: job.id,
105-
},
106-
create: {
107-
source: input.source.name,
108-
externalId: input.source.externalId,
109-
rawUrl: input.source.rawUrl,
110-
data: input.source.data,
111-
jobId: job.id,
112-
},
113-
})
114-
115100
return job
116101
}

src/lib/jobs/reddit.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ export async function storeRedditJobPosts(posts: Array<any>) {
213213
source: {
214214
name: 'reddit',
215215
externalId: post.url, // Use URL as external ID since Reddit doesn't provide a better ID
216-
rawUrl: post.url,
217216
data: post,
218217
},
219218
}

src/lib/jobs/web3career.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export async function storeWeb3CareerJobs(jobs: any[]) {
4747
source: {
4848
name: 'web3career',
4949
externalId: job.id ? String(job.id) : undefined,
50-
rawUrl: job.apply_url,
5150
data: job,
5251
},
5352
}

0 commit comments

Comments
 (0)