mirror of
https://github.com/cheveguerra/Whaticket.git
synced 2026-04-21 13:09:14 +00:00
Initial commit
This commit is contained in:
20
backend/src/helpers/GetDefaultWhatsAppByUser.ts
Normal file
20
backend/src/helpers/GetDefaultWhatsAppByUser.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import User from "../models/User";
|
||||
import Whatsapp from "../models/Whatsapp";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
const GetDefaultWhatsAppByUser = async (
|
||||
userId: number
|
||||
): Promise<Whatsapp | null> => {
|
||||
const user = await User.findByPk(userId, {include: ["whatsapp"]});
|
||||
if( user === null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(user.whatsapp !== null) {
|
||||
logger.info(`Found whatsapp linked to user '${user.name}' is '${user.whatsapp.name}'.`);
|
||||
}
|
||||
|
||||
return user.whatsapp;
|
||||
};
|
||||
|
||||
export default GetDefaultWhatsAppByUser;
|
||||
Reference in New Issue
Block a user