👔 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:
@ -12,9 +12,11 @@ build_app:
|
||||
- bun i
|
||||
- bun run route:sync
|
||||
- bun build --compile --minify-whitespace --minify-syntax --target bun --outfile "server-compiled" ./src/index.ts
|
||||
- echo $CI_JOB_ID > build_job_id.txt
|
||||
artifacts:
|
||||
paths:
|
||||
- server-compiled
|
||||
- build_job_id.txt
|
||||
expire_in: 1 hour
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
@ -26,7 +28,9 @@ create_release:
|
||||
- job: build_app
|
||||
artifacts: true
|
||||
script:
|
||||
- echo "Creating release and uploading server-compiled... (link:\ ${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/server-compiled)"
|
||||
- echo "Creating release and uploading server-compiled..."
|
||||
- export BUILD_JOB_ID=$(cat build_job_id.txt)
|
||||
- echo "Using BUILD_JOB_ID=$BUILD_JOB_ID"
|
||||
release:
|
||||
name: "Release $CI_COMMIT_TAG"
|
||||
tag_name: "$CI_COMMIT_TAG"
|
||||
@ -34,6 +38,6 @@ create_release:
|
||||
assets:
|
||||
links:
|
||||
- name: "server-compiled"
|
||||
url: "${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/server-compiled"
|
||||
url: "${CI_PROJECT_URL}/-/jobs/${BUILD_JOB_ID}/artifacts/raw/server-compiled"
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
|
||||
@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
@ -19,7 +19,7 @@ export const findUserService = async (payload: getUserDataService) => {
|
||||
if (!repoFn) throw new AppError(503, "Repository handler not found");
|
||||
|
||||
// Retrieving user data using the associated repository, if user not found return 404 response
|
||||
const userData = await repoFn(payload.identifier);
|
||||
const userData = await repoFn(payload.identifier, payload.options.include);
|
||||
if (!userData) throw new AppError(404, "User not found");
|
||||
|
||||
// Define verbosity levels
|
||||
|
||||
@ -5,8 +5,9 @@ export interface getUserDataService {
|
||||
}
|
||||
export interface getUserDataOptions {
|
||||
verbosity: "exists" | "basic" | "full";
|
||||
include?: ("preference" | "roles")[];
|
||||
include?: getUserDataIncludeOptions[];
|
||||
}
|
||||
export type getUserDataIncludeOptions = "preference" | "roles";
|
||||
|
||||
export interface createUserViaRegisterInput {
|
||||
name: string;
|
||||
|
||||
Reference in New Issue
Block a user