FPT-Capstone-Group / Smart_Parking_Server

Server to Manage bike's ownership physical card, application and parking session
0 stars 0 forks source link

Push Notification #27

Open trongtomo opened 11 months ago

trongtomo commented 11 months ago

@Datnqse62453 Thiếu gì add vô

trongtomo commented 11 months ago

check xem xài firebase tuowng tự nv đúng k @Datnqse62453

import admin from 'firebase-admin';
import serviceAccount from 'path/to/serviceAccountKey.json'; // Replace with your service account key

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
});

Khi update Regis

// ....
    const newBike = await createBikeFromRegistration(registration, t);
    const newOwner = await createOwnerFromRegistration(
      registration,
      newBike,
      t
    );
    // Send notification to the user
    const message = {
      data: {
        // You can customize the data payload as needed
        title: 'Registration Updated',
        body: 'Your registration has been updated successfully.',
      },
      token: associatedUser.firebaseToken, // Assuming you have a field like 'firebaseToken' in your User model
    };

    await admin.messaging().send(message);
// ...