docs
functions
Firestore
increment
/**
 * Incrementa um valor no Firestore.
 *
 * @param [n=1] - O valor a ser incrementado. O valor padrão é 1.
 * @returns Retorna um objeto `FieldValue` que incrementa o valor no Firestore.
 */
function increment(n?: number): FieldValue;

Uso

import { increment, 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 updatePostCommentsCountOnCreate = postCommentCollection.onCreate(async snap => {
  const postComment: PostComment = ofFirestore(snap);
 
  const postRepository = container.resolve(PostRepository);
  await postRepository.update({
    id: postComment.postId,
    commentsCount: increment()
  });
});