Skip to content

Commit

Permalink
fix(classes): update announcement details
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao authored Dec 3, 2022
1 parent 998ec2a commit ec7ebf6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
14 changes: 11 additions & 3 deletions src/classes/Announcement.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import { getFirestore } from "firebase-admin/firestore";
import { getFirestore } from 'firebase-admin/firestore';

const db = getFirestore(); //get default database

export class Announcement {
id;
data;
appTarget;
expiredDate;
isDraft;
publishedDate;

constructor() {}

loadDetails = async (id) => {
const announcementRef = db.collection("announcements").doc(id);
const announcementRef = db.collection('announcements').doc(id);
const announcementSnap = await announcementRef.get();

const dbItem = announcementSnap.data();

const announcement = new Announcement();
announcement.id = id;
announcement.data = { ...dbItem };
announcement.data = dbItem.data;
announcement.appTarget = dbItem.appTarget;
announcement.expiredDate = dbItem.expiredDate;
announcement.isDraft = dbItem.isDraft;
announcement.publishedDate = dbItem.publishedDate;

return announcement;
};
Expand Down
18 changes: 9 additions & 9 deletions src/classes/Users.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getAuth } from "firebase-admin/auth";
import { getFirestore } from "firebase-admin/firestore";
import { decryptData } from "../utils/encryption-utils.js";
import { sendVerificationEmail } from "../utils/sendEmail.js";
import { User } from "./User.js";
import { getAuth } from 'firebase-admin/auth';
import { getFirestore } from 'firebase-admin/firestore';
import { decryptData } from '../utils/encryption-utils.js';
import { sendVerificationEmail } from '../utils/sendEmail.js';
import { User } from './User.js';

const db = getFirestore(); //get default database

const getUsers = async () => {
const userRef = db.collection("users");
const userRef = db.collection('users');
const snapshot = await userRef.get();

const tmpUsers = [];
Expand Down Expand Up @@ -110,18 +110,18 @@ class clsUsers {
const data = {
about: {
name: fullname,
role: "vip",
role: 'vip',
user_uid: userEmail,
},
};

await db.collection("users").add(data);
await db.collection('users').add(data);

await this.loadAll();
};

delete = async (userId, authId) => {
await db.collection("users").doc(userId).delete();
await db.collection('users').doc(userId).delete();

// remove from auth if qualified
if (authId) await getAuth().deleteUser(authId);
Expand Down

0 comments on commit ec7ebf6

Please sign in to comment.