Skip to content

Commit 4c231d0

Browse files
Removed JobSource table & updated queries & models.
1 parent 3d65f00 commit 4c231d0

File tree

5 files changed

+64
-122
lines changed

5 files changed

+64
-122
lines changed

src/jobs/dto/create-job.dto.ts

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,46 +39,6 @@ export class JobMetadataDto {
3939
value: string;
4040
}
4141

42-
/**
43-
* DTO for job source information
44-
* Tracks where the job listing came from and stores original data
45-
*/
46-
export class JobSourceDto {
47-
@ApiProperty({
48-
description: 'Source system name',
49-
example: 'reddit',
50-
})
51-
@IsString()
52-
@IsNotEmpty()
53-
source: string;
54-
55-
@ApiProperty({
56-
description: 'External ID from source system',
57-
example: 'reddit_post_123',
58-
required: false,
59-
})
60-
@IsOptional()
61-
@IsString()
62-
externalId?: string;
63-
64-
@ApiProperty({
65-
description: 'Original URL from source system',
66-
example: 'https://reddit.com/r/jobs/post/123',
67-
required: false,
68-
})
69-
@IsOptional()
70-
@IsUrl()
71-
rawUrl?: string;
72-
73-
@ApiProperty({
74-
description: 'Raw source data as JSON',
75-
example: '{"upvotes": 45, "comments": 12}',
76-
required: false,
77-
})
78-
@IsOptional()
79-
data?: any;
80-
}
81-
8242
/**
8343
* Create Job DTO
8444
*
@@ -216,15 +176,20 @@ export class CreateJobDto {
216176
@Type(() => JobMetadataDto)
217177
metadata?: JobMetadataDto[];
218178

219-
@ApiProperty({
220-
description: 'Job source information',
221-
required: false,
222-
type: [JobSourceDto],
223-
})
224-
@GraphQLField(() => [JobSourceDto], { nullable: true })
179+
@ApiProperty({ description: 'Source system name', example: 'reddit', required: false })
180+
@GraphQLField({ nullable: true })
225181
@IsOptional()
226-
@IsArray()
227-
@ValidateNested({ each: true })
228-
@Type(() => JobSourceDto)
229-
sources?: JobSourceDto[];
182+
@IsString()
183+
source?: string;
184+
185+
@ApiProperty({ description: 'External ID from source system', example: 't3_abc123', required: false })
186+
@GraphQLField({ nullable: true })
187+
@IsOptional()
188+
@IsString()
189+
externalId?: string;
190+
191+
@ApiProperty({ description: 'Raw source data as JSON', required: false })
192+
@GraphQLField({ nullable: true })
193+
@IsOptional()
194+
data?: any;
230195
}

src/jobs/job.service.ts

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ export class JobService {
4040
isRemote?: boolean;
4141
tags?: string[];
4242
metadata?: Record<string, string>;
43-
source!: {
44-
name: string;
45-
externalId?: string;
46-
rawUrl?: string;
47-
data?: any;
48-
};
43+
// Flattened source fields
44+
source?: string;
45+
externalId?: string;
46+
data?: any;
4947
};
5048

5149
/**
@@ -63,12 +61,10 @@ export class JobService {
6361
isRemote?: boolean;
6462
tags?: string[];
6563
metadata?: Record<string, string>;
66-
source: {
67-
name: string;
68-
externalId?: string;
69-
rawUrl?: string;
70-
data?: any;
71-
};
64+
// Flattened source fields
65+
source?: string;
66+
externalId?: string;
67+
data?: any;
7268
}): Promise<Job> {
7369
let companyRecord = null;
7470
if (input.company) {
@@ -90,7 +86,11 @@ export class JobService {
9086
isRemote: input.isRemote,
9187
company: companyRecord ? { connect: { id: companyRecord.id } } : undefined,
9288
updatedAt: new Date(),
93-
},
89+
// write source fields directly on Job
90+
source: input.source,
91+
externalId: input.externalId,
92+
data: input.data,
93+
} as any,
9494
create: {
9595
title: input.title,
9696
author: input.author,
@@ -100,7 +100,11 @@ export class JobService {
100100
isRemote: input.isRemote,
101101
url: input.url,
102102
company: companyRecord ? { connect: { id: companyRecord.id } } : undefined,
103-
},
103+
// write source fields directly on Job
104+
source: input.source,
105+
externalId: input.externalId,
106+
data: input.data,
107+
} as any,
104108
});
105109

106110
// Upsert tags (many-to-many via JobTag)
@@ -130,28 +134,6 @@ export class JobService {
130134
}
131135
}
132136

133-
// Upsert job source
134-
await this.prisma.jobSource.upsert({
135-
where: {
136-
source_externalId: {
137-
source: input.source.name,
138-
externalId: input.source.externalId || '',
139-
},
140-
},
141-
update: {
142-
rawUrl: input.source.rawUrl,
143-
data: input.source.data,
144-
jobId: job.id,
145-
},
146-
create: {
147-
source: input.source.name,
148-
externalId: input.source.externalId,
149-
rawUrl: input.source.rawUrl,
150-
data: input.source.data,
151-
jobId: job.id,
152-
},
153-
});
154-
155137
return job;
156138
}
157139

@@ -171,8 +153,21 @@ export class JobService {
171153
* Creates a job with associated company, tags, and metadata
172154
*/
173155
async create(createJobDto: CreateJobDto, userId?: number): Promise<Job> {
174-
const { title, companyName, companyId, author, location, url, description, isRemote, tags, metadata, sources } =
175-
createJobDto;
156+
const {
157+
title,
158+
companyName,
159+
companyId,
160+
author,
161+
location,
162+
url,
163+
description,
164+
isRemote,
165+
tags,
166+
metadata,
167+
source,
168+
externalId,
169+
data,
170+
} = createJobDto as any;
176171

177172
let company: any = null;
178173
if (companyId) {
@@ -202,6 +197,10 @@ export class JobService {
202197
description,
203198
isRemote,
204199
postedAt: createJobDto.postedAt || new Date(),
200+
// flattened source fields
201+
source,
202+
externalId,
203+
data,
205204
// Create associated tags
206205
tags: tags?.length
207206
? {
@@ -224,18 +223,7 @@ export class JobService {
224223
})),
225224
}
226225
: undefined,
227-
// Create source entries
228-
sources: sources?.length
229-
? {
230-
create: sources.map((source) => ({
231-
source: source.source,
232-
externalId: source.externalId,
233-
rawUrl: source.rawUrl,
234-
data: source.data,
235-
})),
236-
}
237-
: undefined,
238-
},
226+
} as any,
239227
include: {
240228
company: true,
241229
tags: {
@@ -244,7 +232,6 @@ export class JobService {
244232
},
245233
},
246234
metadata: true,
247-
sources: true,
248235
},
249236
});
250237

@@ -332,7 +319,6 @@ export class JobService {
332319
},
333320
},
334321
metadata: true,
335-
sources: true,
336322
},
337323
}),
338324
this.prisma.job.count({ where }),
@@ -361,7 +347,6 @@ export class JobService {
361347
},
362348
},
363349
metadata: true,
364-
sources: true,
365350
},
366351
});
367352

@@ -477,7 +462,6 @@ export class JobService {
477462
// Delete related data first
478463
await prisma.jobTag.deleteMany({ where: { jobId: id } });
479464
await prisma.jobMetadata.deleteMany({ where: { jobId: id } });
480-
await prisma.jobSource.deleteMany({ where: { jobId: id } });
481465

482466
// Delete the job
483467
await prisma.job.delete({ where: { id } });
@@ -522,7 +506,6 @@ export class JobService {
522506
},
523507
},
524508
metadata: true,
525-
sources: true,
526509
},
527510
}),
528511
this.prisma.job.count({ where }),
@@ -574,7 +557,6 @@ export class JobService {
574557
},
575558
},
576559
metadata: true,
577-
sources: true,
578560
},
579561
}),
580562
this.prisma.job.count({ where }),

src/jobs/reddit.service.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ export class RedditService {
6666
upvotes: post.upvotes ? String(post.upvotes) : '0',
6767
downvotes: post.downvotes ? String(post.downvotes) : '0',
6868
},
69-
source: {
70-
name: 'reddit',
71-
externalId: post.url,
72-
rawUrl: post.url,
73-
data: post,
74-
},
75-
};
69+
// flattened source fields
70+
source: 'reddit',
71+
externalId: post.url,
72+
data: post,
73+
} as any;
7674
// Check if job already exists - if so, skip it but continue processing others
7775
const exists = await this.jobService.jobExists(post.url);
7876
if (exists) {

src/jobs/web3career.service.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ export class Web3CareerService {
4646
city: job.city || '',
4747
date_epoch: job.date_epoch ? String(job.date_epoch) : '',
4848
},
49-
source: {
50-
name: 'web3career',
51-
externalId: job.id ? String(job.id) : undefined,
52-
rawUrl: job.apply_url,
53-
data: job,
54-
},
55-
};
49+
// flattened source fields
50+
source: 'web3career',
51+
externalId: job.id ? String(job.id) : undefined,
52+
data: job,
53+
} as any;
5654
// Check if job already exists - if so, skip it but continue processing others
5755
const exists = await this.jobService.jobExists(job.apply_url);
5856
if (exists) {

src/metadata.ts

Lines changed: 1 addition & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)