👔 add include option on find user repository
add include option for spicify which associated data that want to retrive along with user data response
This commit is contained in:
@ -1,9 +1,22 @@
|
||||
import { userModel } from "../../user.model";
|
||||
import {
|
||||
getUserDataIncludeOptions,
|
||||
getUserDataOptions,
|
||||
} from "../../user.types";
|
||||
|
||||
export const findUserByEmailRepository = async (email: string) => {
|
||||
export const findUserByEmailRepository = async (
|
||||
email: string,
|
||||
include?: getUserDataOptions["include"]
|
||||
) => {
|
||||
return await userModel.findUnique({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
include: include
|
||||
? (Object.fromEntries(include.map((key) => [key, true])) as Record<
|
||||
getUserDataIncludeOptions,
|
||||
true
|
||||
>)
|
||||
: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,9 +1,22 @@
|
||||
import { userModel } from "../../user.model";
|
||||
import {
|
||||
getUserDataIncludeOptions,
|
||||
getUserDataOptions,
|
||||
} from "../../user.types";
|
||||
|
||||
export const findUserByIdRepository = async (id: string) => {
|
||||
export const findUserByIdRepository = async (
|
||||
id: string,
|
||||
include?: getUserDataOptions["include"]
|
||||
) => {
|
||||
return await userModel.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: include
|
||||
? (Object.fromEntries(include.map((key) => [key, true])) as Record<
|
||||
getUserDataIncludeOptions,
|
||||
true
|
||||
>)
|
||||
: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,9 +1,22 @@
|
||||
import { userModel } from "../../user.model";
|
||||
import {
|
||||
getUserDataIncludeOptions,
|
||||
getUserDataOptions,
|
||||
} from "../../user.types";
|
||||
|
||||
export const findUserByUsernameRepository = async (username: string) => {
|
||||
export const findUserByUsernameRepository = async (
|
||||
username: string,
|
||||
include?: getUserDataOptions["include"]
|
||||
) => {
|
||||
return await userModel.findUnique({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
include: include
|
||||
? (Object.fromEntries(include.map((key) => [key, true])) as Record<
|
||||
getUserDataIncludeOptions,
|
||||
true
|
||||
>)
|
||||
: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user