Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Support replacements on time collection #48

Conversation

nicolassanmar
Copy link
Collaborator

@nicolassanmar nicolassanmar commented Jul 10, 2024

Support the replaceOne and findOneAndReplace methods on time collections. The replaceOne and findOneAndReplace methods will overwrite the createdAt and updatedAt fields with a new Date value

@nicolassanmar nicolassanmar force-pushed the feat/support-replacements-on-time-collection branch from 1f61014 to 831aa95 Compare July 10, 2024 18:07
@@ -45,8 +47,9 @@ export const convertToTimeCollection = <TSchema extends Document>(
} as any,
}
},
preReplace: () => {
throw Error('Does not support replace')
preReplace: (obj: WithoutId<TSchema>): WithoutId<WithTime<TSchema>> => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the input and output types here to be consistent with this file, but none of these are required as they are inferred from the Converter type definition:

type Converter<
TInsertSchema0 extends Document,
TInsertSchema1 extends Document,
TUpdateSchema0 extends Document,
TUpdateSchema1 extends Document,
TReplaceSchema0 extends Document,
TReplaceSchema1 extends Document,
TsFilterSchema extends DocumentWithId,
TReturnSchema extends DocumentWithId
> = {
preInsert: (
obj: OptionalUnlessRequiredId<TInsertSchema1>
) => OptionalUnlessRequiredId<TInsertSchema0>
preUpdate: (
_: TsUpdate<TUpdateSchema1>,
options: TsUpdateOptions | undefined
) => TsUpdate<TUpdateSchema0>
preReplace: (_: WithoutId<TReplaceSchema1>) => WithoutId<TReplaceSchema0>
postFind: (_: TReturnSchema) => TReturnSchema
preFilter: (_: TsFilter<TsFilterSchema>) => TsFilter<TsFilterSchema>
}

@nicolassanmar nicolassanmar force-pushed the feat/support-replacements-on-time-collection branch from 831aa95 to df06363 Compare July 10, 2024 18:41
@tianhuil tianhuil merged commit 8a2595a into tianhuil:main Jul 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants