1- import * as functions from 'firebase-functions' ;
2- import { firestore } from 'firebase-admin' ;
31import { notifyReviewStatusChangeMessageToDiscordAndGAS } from '../utils/notification' ;
2+ import { CloudEvent } from 'firebase-functions' ;
3+ import { MessagePublishedData } from 'firebase-functions/pubsub' ;
4+ import { Firestore , DocumentSnapshot } from 'firebase-admin/firestore' ;
5+ import { Auth } from 'firebase-admin/auth' ;
46
57export const review = async (
6- message : functions . pubsub . Message ,
7- db : firestore . Firestore
8+ message : CloudEvent < MessagePublishedData > ,
9+ db : Firestore ,
10+ auth : Auth
811) : Promise < void > => {
9- const data = JSON . parse ( Buffer . from ( message . data , 'base64' ) . toString ( ) ) ;
12+ const data = JSON . parse (
13+ Buffer . from ( message . data . message . data , 'base64' ) . toString ( )
14+ ) ;
1015 const definitionId = data . definitionId ;
1116
1217 const definitionDocumentSnapshot = await db
@@ -46,6 +51,7 @@ export const review = async (
4651 } ) ;
4752 if ( sameProductNameExists ) {
4853 await reject (
54+ auth ,
4955 definitionDocumentSnapshot ,
5056 'The same keyboard definition (Vendor ID, Product ID and Product Name) already exists.'
5157 ) ;
@@ -54,27 +60,30 @@ export const review = async (
5460 requestIsUnique ( definitionDocumentSnapshot ) ;
5561} ;
5662
57- const requestIsUnique = (
58- definitionDocument : firestore . DocumentSnapshot
59- ) : void => {
63+ const requestIsUnique = ( definitionDocument : DocumentSnapshot ) : void => {
6064 const data = definitionDocument . data ( ) ! ;
6165 const message = `The Vendor ID, Product ID and Product Name of the keyboard ${ data . name } (${ data . product_name } ) (${ definitionDocument . id } ) is unique.` ;
6266 console . log ( message ) ;
6367} ;
6468
6569const reject = async (
66- definitionDocument : firestore . DocumentSnapshot ,
70+ auth : Auth ,
71+ definitionDocument : DocumentSnapshot ,
6772 reason : string
6873) : Promise < void > => {
6974 await definitionDocument . ref . update ( {
7075 status : 'rejected' ,
7176 reject_reason : reason ,
7277 updated_at : new Date ( ) ,
7378 } ) ;
74- await notifyReviewStatusChangeMessageToDiscordAndGAS ( definitionDocument . id , {
75- name : definitionDocument . data ( ) ! . name ,
76- author_uid : definitionDocument . data ( ) ! . author_uid ,
77- product_name : definitionDocument . data ( ) ! . product_name ,
78- status : 'rejected' ,
79- } ) ;
79+ await notifyReviewStatusChangeMessageToDiscordAndGAS (
80+ auth ,
81+ definitionDocument . id ,
82+ {
83+ name : definitionDocument . data ( ) ! . name ,
84+ author_uid : definitionDocument . data ( ) ! . author_uid ,
85+ product_name : definitionDocument . data ( ) ! . product_name ,
86+ status : 'rejected' ,
87+ }
88+ ) ;
8089} ;
0 commit comments