mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 13:13:54 +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 WithIsEditable<T> = T & {
|
||||
isEditable: boolean
|
||||
}
|
||||
|
||||
function computeIsEditable(
|
||||
profileInput: offersProfile,
|
||||
editToken?: string
|
||||
): WithIsEditable<offersProfile> {
|
||||
return {
|
||||
...profileInput,
|
||||
isEditable: profileInput.editToken === editToken,
|
||||
}
|
||||
}
|
||||
|
||||
export const offersProfileRouter = createRouter()
|
||||
.query('listOne', {
|
||||
input: z.object({
|
||||
@ -102,21 +116,8 @@ export const offersProfileRouter = createRouter()
|
||||
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
|
||||
function computeIsEditable(
|
||||
profileInput: offersProfile
|
||||
): WithIsEditable<offersProfile> {
|
||||
return {
|
||||
...profileInput,
|
||||
isEditable: profileInput["editToken" as keyof typeof profileInput] === input.token,
|
||||
}
|
||||
}
|
||||
return result ? computeIsEditable(result) : result;
|
||||
return result ? computeIsEditable(result, input.token) : result;
|
||||
},
|
||||
})
|
||||
.mutation('create', {
|
||||
|
Reference in New Issue
Block a user