mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 21:23:14 +08:00
[offers][chore] refactor isEditable code
This commit is contained in:
@ -51,6 +51,20 @@ const education = z.object({
|
|||||||
type: z.string().optional(),
|
type: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
type WithIsEditable<T> = T & {
|
||||||
|
isEditable: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
function computeIsEditable(
|
||||||
|
profileInput: offersProfile,
|
||||||
|
editToken?: string
|
||||||
|
): WithIsEditable<offersProfile> {
|
||||||
|
return {
|
||||||
|
...profileInput,
|
||||||
|
isEditable: profileInput.editToken === editToken,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const offersProfileRouter = createRouter()
|
export const offersProfileRouter = createRouter()
|
||||||
.query('listOne', {
|
.query('listOne', {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
@ -102,21 +116,8 @@ export const offersProfileRouter = createRouter()
|
|||||||
id: input.profileId,
|
id: input.profileId,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Extend the T generic with the fullName attribute
|
|
||||||
type WithIsEditable<T> = T & {
|
|
||||||
isEditable: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take objects that satisfy FirstLastName and computes a full name
|
return result ? computeIsEditable(result, input.token) : result;
|
||||||
function computeIsEditable(
|
|
||||||
profileInput: offersProfile
|
|
||||||
): WithIsEditable<offersProfile> {
|
|
||||||
return {
|
|
||||||
...profileInput,
|
|
||||||
isEditable: profileInput["editToken" as keyof typeof profileInput] === input.token,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result ? computeIsEditable(result) : result;
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.mutation('create', {
|
.mutation('create', {
|
||||||
|
Reference in New Issue
Block a user