@@ -84,9 +84,13 @@ export const internalApproveSuggestion = internalMutation({
8484
8585export const approveSuggestion = adminAuthAction ( {
8686 args : {
87- suggestionId : v . id ( 'suggestions' )
87+ suggestionId : v . id ( 'suggestions' ) ,
88+ token : v . union ( v . string ( ) , v . null ( ) )
8889 } ,
89- handler : async ( { runQuery, runMutation, runAction } , { suggestionId } ) => {
90+ handler : async (
91+ { runQuery, runMutation, runAction } ,
92+ { suggestionId, token }
93+ ) => {
9094 const suggestion = await runQuery ( internal . suggestions . getSuggestionById , {
9195 suggestionId
9296 } )
@@ -151,12 +155,23 @@ export const approveSuggestion = adminAuthAction({
151155 type : 'suggestionApproved'
152156 } )
153157 }
154- if ( userSettings ?. suggestionApprovedEmail ) {
155- // Todo: send email
156- // await runAction(internal.email.sendEmail, {
157- // subject: 'Suggestion Approved',
158- // html: `<p>Your suggestion for <b>${suggestion.name}</b> has been approved.</p>`
159- // })
158+ if ( userSettings ?. suggestionApprovedEmail && token ) {
159+ const user = await runQuery ( internal . users . getUserById , {
160+ userId : suggestion . userId
161+ } )
162+ if ( ! user ) return true
163+ await runAction ( internal . email . sendEmailToUser , {
164+ subject : 'Suggestion Approved' ,
165+ 166+ to : user . email ,
167+ type : 'suggestionApprovedEmail' ,
168+ data : {
169+ suggestion : suggestion . name ,
170+ type : suggestion . type ,
171+ points : pointsPerSuggestionType [ suggestion . type ]
172+ } ,
173+ token
174+ } )
160175 }
161176 }
162177
0 commit comments