Skip to content

Commit de90fee

Browse files
committed
feat: support url parsing
1 parent 5f6a965 commit de90fee

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/common/profile/import.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export const importUserExperienceCertification = async ({
269269
started_at: startedAt,
270270
ended_at: endedAt,
271271
flags,
272+
url,
272273
} = userExperience;
273274

274275
const insertResult = await con
@@ -284,6 +285,7 @@ export const importUserExperienceCertification = async ({
284285
title,
285286
startedAt,
286287
endedAt,
288+
url,
287289
}),
288290
);
289291

@@ -312,6 +314,7 @@ export const importUserExperienceProject = async ({
312314
ended_at: endedAt,
313315
skills,
314316
flags,
317+
url,
315318
} = userExperience;
316319

317320
const insertResult = await con.getRepository(UserExperienceProject).insert(
@@ -322,6 +325,7 @@ export const importUserExperienceProject = async ({
322325
description,
323326
startedAt,
324327
endedAt,
328+
url,
325329
}),
326330
);
327331

src/common/schema/common.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,21 @@ export const paginationSchema = z.object({
1616
});
1717

1818
export type PaginationArgs = z.infer<typeof paginationSchema>;
19+
20+
const urlStartRegexMatch = /^https?:\/\//;
21+
22+
// match http(s) urls and partials like daily.dev (without protocol )
23+
export const urlParseSchema = z.preprocess(
24+
(val) => {
25+
if (typeof val === 'string') {
26+
return val.match(urlStartRegexMatch) ? val : `https://${val}`;
27+
}
28+
29+
return val;
30+
},
31+
z.url({
32+
protocol: /^https?$/,
33+
hostname: z.regexes.domain,
34+
normalize: true,
35+
}),
36+
);

src/common/schema/profile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import z from 'zod';
22
import { UserExperienceType } from '../../entity/user/experiences/types';
3-
import { paginationSchema } from './common';
3+
import { paginationSchema, urlParseSchema } from './common';
44

55
export const userExperiencesSchema = z
66
.object({
@@ -161,6 +161,7 @@ export const userExperienceCertificationImportSchema = z.object({
161161
started_at: z.coerce.date().default(() => new Date()),
162162
ended_at: z.coerce.date().nullish().default(null),
163163
flags: z.object({ import: z.string() }).partial().optional(),
164+
url: urlParseSchema.nullish(),
164165
});
165166

166167
export const userExperienceProjectImportSchema = z.object({
@@ -178,4 +179,5 @@ export const userExperienceProjectImportSchema = z.object({
178179
.nullish()
179180
.transform((n) => (n === null ? undefined : n)),
180181
flags: z.object({ import: z.string() }).partial().optional(),
182+
url: urlParseSchema.nullish(),
181183
});

0 commit comments

Comments
 (0)