Skip to content

Commit

Permalink
Retrieve product data from database
Browse files Browse the repository at this point in the history
Currently grabbing all relevant fields.
Once workflow backend is implemented, should change to only grab data needed based on the state of the task in the workflow.
  • Loading branch information
FyreByrd committed Sep 6, 2024
1 parent e10b985 commit 942ae7e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async (event) => {
const session = await event.locals.auth();
//----temporary, remove later-----
const products = await prisma.products.findMany({ select: { Id: true }});
console.log(products);
//--------------------------------
const tasks = await prisma.userTasks.findMany({
where: {
UserId: session?.user.userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@ type Fields = {
email?: string; //Product.Project.Owner.Email
name: string; //Product.Project.Name
description: string; //Product.Project.Description
store?: string; //Product.Store.Name
store?: string; //Product.Store.Description
listingLanguage?: string; //Product.StoreLanguage.Name
projectURL?: string; //Product.Project.WorkflowAppProjectURL?
product?: string; //Product.ProductDefinition.Name?
appType?: string; //Product.ProductDefinition.ApplicationTypes.Name
langCode?: string; //Product.Project.Language?
projectURL?: string; //Product.Project.WorkflowAppProjectURL
product?: string; //Product.ProductDefinition.Description
appType?: string; //Product.ProductDefinition.ApplicationTypes.Description
langCode?: string; //Product.Project.Language
}

//replace with Product.ProductArtifacts
type File = {
BuildId: number;
Type: string;
Size: string;
URL: string;
Id: number;
};

//replace with Product.Project.Reviewers
type User = {
Id: number;
Expand All @@ -31,21 +22,83 @@ type User = {
};

export const load = (async ({ params, url, locals }) => {
const userInfo = (await locals.auth())?.user;
console.log(userInfo);
const product = await prisma.products.findUnique({
where: {
Id: params.product_id
},
select: {
Project: {
select: {
Name: true,
Description: true,
WorkflowAppProjectUrl: true,
Language: true,
Owner: {
select: {
Name: true,
Email: true
}
},
Reviewers: {
select: {
Id: true,
Name: true,
Email: true
}
}
}
},
Store: {
select: {
Description: true
}
},
StoreLanguage: {
select: {
Name: true
}
},
ProductDefinition: {
select: {
Name: true,
ApplicationTypes: {
select: {
Description: true
}
}
}
},
ProductArtifacts: {
select: {
ProductBuildId: true,
ContentType: true,
FileSize: true,
Url: true,
Id: true
}
}
}
});

const products = await prisma.products.findMany();
console.log(products);
return {
actions: [],
taskTitle: "Waiting",
instructions: "waiting",
//filter fields based on task
//filter fields/files/reviewers based on task once workflows are implemented
//possibly filter in the original query to increase database efficiency
fields: {
name: "Test Project",
description: "a test project"
user: product?.Project.Owner.Name,
email: product?.Project.Owner.Email,
name: product?.Project.Name,
description: product?.Project.Description,
store: product?.Store?.Description,
listingLanguage: product?.StoreLanguage?.Name,
projectURL: product?.Project.WorkflowAppProjectUrl,
product: product?.ProductDefinition.Name,
appType: product?.ProductDefinition.ApplicationTypes.Description,
langCode: product?.Project.Language
} as Fields,
files: [] as File[],
reviewers: [] as User[]
files: product?.ProductArtifacts,
reviewers: product?.Project.Reviewers
}
}) satisfies PageServerLoad;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div class="p-5">
<form>
{#if data.actions?.length > 0}
{#if data.actions?.length}
<div class="flex flex-row gap-x-3">
{#each data.actions as action}
<input type="submit" class="btn" value={action}>
Expand Down Expand Up @@ -109,13 +109,13 @@
<svelte:component this={instructions[data.instructions]} />
</div>
{/if}
{#if data.files?.length > 0}
{#if data?.files?.length}
<div class="overflow-x-auto max-h-96">
<h3>Files</h3>
<SortTable items={data.files} />
</div>
{/if}
{#if data.reviewers?.length > 0}
{#if data?.reviewers?.length}
<div class="overflow-x-auto max-h-96">
<h3>Reviewers</h3>
<SortTable items={data.reviewers} />
Expand Down

0 comments on commit 942ae7e

Please sign in to comment.