Created
October 8, 2022 21:50
-
-
Save petrenkoVitaliy/d310719f87903373f1382baf17b1e13d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Conditional<T extends boolean, A1, A2> = T extends true ? A1 : A2; | |
export type Argument<Fn extends (args: any) => any> = Parameters<Fn>[0]; | |
//----- | |
private UpdateMethodType: typeof this.prisma.articleVersion.update; | |
update<T extends boolean>(options: { | |
code: string; | |
actual?: true | null; | |
archived?: boolean; | |
enabled?: boolean; | |
isExtended?: T; | |
}) { | |
const updateOptions = { | |
where: { | |
code: options.code, | |
}, | |
data: { | |
actual: options.actual, | |
archived: options.archived, | |
enabled: options.enabled, | |
}, | |
}; | |
const include = { | |
schema: { | |
include: { | |
body: true, | |
header: true, | |
}, | |
}, | |
}; | |
return this.updateExtended({ | |
updateOptions, | |
include, | |
isExtended: options.isExtended, | |
}); | |
} | |
private updateExtended< | |
T extends boolean, | |
P extends Pick<Argument<typeof this.UpdateMethodType>, 'data' | 'where'>, | |
R extends Argument<typeof this.UpdateMethodType>['include'], | |
>(options: { updateOptions: P; isExtended?: T; include: R }) { | |
const { updateOptions, include } = options; | |
return this.prisma.articleVersion.update({ | |
...updateOptions, | |
include: options.isExtended ? include : null, | |
}) as Conditional< | |
T, | |
ReturnType<typeof this.UpdateMethodType<typeof updateOptions & { include: typeof include }>>, | |
ReturnType<typeof this.UpdateMethodType<typeof updateOptions>> | |
>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment