starting implementation of user status changing

This commit is contained in:
talksik
2022-03-23 21:09:50 -04:00
parent 3cdb4c896b
commit 500330e02c
6 changed files with 68 additions and 8 deletions
+15 -2
View File
@@ -1,6 +1,7 @@
import { GoogleUserInfo, User } from "@nirvana/core/models";
import { ObjectId } from "mongodb";
import { UserStatus } from "../../core/models/user.model";
import axios from "axios";
import { collections } from "./database.service";
@@ -58,8 +59,9 @@ export class UserService {
}
static async createUserIfNotExists(newUser: User) {
const exists = (await collections.users?.findOne({ id: newUser.googleId }))
?._id;
const exists = (
await collections.users?.findOne({ googleId: newUser.googleId })
)?._id;
if (!exists) {
return await collections.users?.insertOne(newUser);
@@ -78,4 +80,15 @@ export class UserService {
)
).data;
}
static async updateUserStatus(userGoogleId: string, newStatus: UserStatus) {
const query = { googleId: userGoogleId };
const updateDoc = {
$set: { status: newStatus, lastUpdatedDate: new Date() },
};
const resultUpdate = await collections.users?.updateOne(query, updateDoc);
return resultUpdate;
}
}