/**
* Decrementa um valor no Firestore.
*
* @param [n=1] - O valor a ser decrementado. O valor padrão é 1.
* @returns Retorna um objeto `FieldValue` que decrementa o valor no Firestore.
*/
function decrement(n?: number): FieldValue;
Uso
import { decrement, ofFirestore } from '@burand/functions/firestore';
import { firestore } from 'firebase-functions';
import { container } from 'tsyringe';
import { FirestoreCollecionName } from '@config/firestore-collection-name.js';
import { PostComment } from '@models/post-comment.js';
import { PostRepository } from '@repositories/post.repository.js';
const { POST_COMMENTS } = FirestoreCollecionName;
const postCommentCollection = firestore.document(`${POST_COMMENTS}/{postCommentId}`);
export const updatePostCommentsCountOnDelete = postCommentCollection.onDelete(async snap => {
const postComment: PostComment = ofFirestore(snap);
const postRepository = container.resolve(PostRepository);
await postRepository.update({
id: postComment.postId,
commentsCount: decrement()
});
});