Skip to content

Commit

Permalink
Merge pull request #211 from wizelineacademy/sqs-integration-with-lalo
Browse files Browse the repository at this point in the history
Sqs integration with lalo
  • Loading branch information
pedroalonsoms authored Jun 7, 2024
2 parents 5745c38 + f6e46a4 commit 2d38dc1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Install SST
run: |
wget https://github.com/sst/ion/releases/download/v0.0.399/sst-linux-amd64.deb
wget https://github.com/sst/ion/releases/download/v0.0.411/sst-linux-amd64.deb
sudo dpkg -i sst-linux-amd64.deb
- name: Install Bun
Expand Down
50 changes: 31 additions & 19 deletions app/(base)/pcp/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ const PCP = () => {
refetchOnWindowFocus: false,
});

const scheduledAt = sprintSurveyQuery.data?.scheduledAt;
const formattedDate = scheduledAt
? new Date(scheduledAt).toLocaleDateString("es-ES")
: "";
const formatDate = (date: Date) => {
return new Date(date).toLocaleString("default", {
day: "2-digit",
month: "short",
year: "numeric",
});
};

const progressPercentage = 100;

Expand All @@ -76,7 +79,12 @@ const PCP = () => {
<div className="flex items-center justify-between">
<p className=" mb-2 text-3xl font-semibold">Personal Career Plan</p>
<p className=" mb-2 text-xl font-medium text-graySubtitle">
{`Sprint ${formattedDate}`}
{sprintSurveyQuery.data &&
typeof sprintSurveyQuery.data === "string"
? sprintSurveyQuery.data
: sprintSurveyQuery.isLoading || !sprintSurveyQuery.data
? "loading..."
: `Sprint ${formatDate(sprintSurveyQuery.data.scheduledAt as Date)}`}
</p>
</div>
<div className="flex w-full flex-row items-center justify-between gap-4">
Expand All @@ -85,8 +93,9 @@ const PCP = () => {
<div className="relative mt-1">
<Listbox.Button className="relative flex w-full cursor-default items-center justify-between rounded-lg bg-white py-2 pl-3 pr-4 text-left shadow-md focus:outline-none focus-visible:border-indigo-500 focus-visible:ring-2 focus-visible:ring-white/75 focus-visible:ring-offset-2 focus-visible:ring-offset-orange-300 sm:text-sm">
<p className="truncate">
{projectsQuery.data &&
projectsQuery.data.find((p) => p.id === projectId)?.name}
{(projectsQuery.data &&
projectsQuery.data.find((p) => p.id === projectId)?.name) ??
"Personal Improvement"}
</p>
<svg
className="h-4 w-4 fill-current text-gray-700"
Expand All @@ -104,8 +113,8 @@ const PCP = () => {
>
<Listbox.Options className="absolute z-50 mt-1 max-h-56 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black/5 focus:outline-none sm:text-sm">
<Listbox.Option
key={0}
value={0}
key={-1}
value={-1}
className={({ active }) =>
`relative my-1 cursor-default select-none rounded-xl ${
active ? "bg-gray-200 text-black" : "text-gray-900"
Expand Down Expand Up @@ -194,10 +203,10 @@ const PCPTasks = ({ projectId }: { projectId: number }) => {
</button>
</div>

{tasksQuery.isLoading ? (
{tasksQuery.isLoading || !tasksQuery.data ? (
<p>loading...</p>
) : tasksQuery.isError ? (
<NoDataCard text={tasksQuery.error.message} />
) : tasksQuery.data && typeof tasksQuery.data === "string" ? (
<NoDataCard text={tasksQuery.data} />
) : (
tasksQuery.data && (
<div className="mt-2">
Expand Down Expand Up @@ -236,8 +245,8 @@ const PCPTasksDialogContent = ({ projectId }: { projectId: number }) => {
mutationFn: updateTask,
});

if (tasksHistoryQuery.isError) {
return <NoDataCard text={tasksHistoryQuery.error.message} />;
if (tasksHistoryQuery.data && typeof tasksHistoryQuery.data === "string") {
return <NoDataCard text={tasksHistoryQuery.data} />;
}

if (tasksHistoryQuery.isLoading || !tasksHistoryQuery.data) {
Expand Down Expand Up @@ -445,10 +454,10 @@ const PCPResources = ({ projectId }: { projectId: number }) => {
</button>
</div>

{resourcesQuery.isLoading ? (
{resourcesQuery.isLoading || !resourcesQuery.data ? (
<p>loading...</p>
) : resourcesQuery.isError ? (
<NoDataCard text={resourcesQuery.error.message} />
) : resourcesQuery.data && typeof resourcesQuery.data === "string" ? (
<NoDataCard text={resourcesQuery.data} />
) : (
resourcesQuery.data && (
<div className="mt-2">
Expand Down Expand Up @@ -529,8 +538,11 @@ const PCPResourcesDialogContent = ({ projectId }: { projectId: number }) => {
refetchOnWindowFocus: false,
});

if (resourcesHistoryQuery.isError) {
return <NoDataCard text={resourcesHistoryQuery.error.message} />;
if (
resourcesHistoryQuery.data &&
typeof resourcesHistoryQuery.data === "string"
) {
return <NoDataCard text={resourcesHistoryQuery.data} />;
}

if (resourcesHistoryQuery.isLoading || !resourcesHistoryQuery.data) {
Expand Down
33 changes: 17 additions & 16 deletions services/tasks-and-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getCurrentSprintSurvey(projectId: number) {
.orderBy(desc(sprintSurvey.scheduledAt))
.limit(1);

if (!res[0]) throw new Error("No sprint survey was found");
if (!res[0]) return "No sprint survey was found";
return res[0];
}

Expand All @@ -36,18 +36,18 @@ export async function getUserTasksForCurrentSprintByProjectId(
) {
const session = await auth();
const userId = session?.user?.id;
if (!userId) throw new Error("You must be signed in");
if (!userId) return "You must be signed in";

const currentSprintSurvey = await getCurrentSprintSurvey(projectId);

if (typeof currentSprintSurvey === "string") {
return currentSprintSurvey;
}
// check if the sprint is not processed to throw an error
// check if there's no sprint survey results throw an error
// check if all the surveys were answered, so the only one left is the project one

if (!currentSprintSurvey.processed) {
throw new Error(
"Curreny sprint survey was found, but it is not processed yet",
);
return "Curreny sprint survey was found, but it is not processed yet";
}

const tasks = await db
Expand All @@ -62,7 +62,7 @@ export async function getUserTasksForCurrentSprintByProjectId(
.orderBy(asc(pipTask.title));

if (tasks.length === 0) {
throw new Error("No tasks available. Ask your manager for an update.");
return "No tasks available. Ask your manager for an update.";
}

return tasks;
Expand All @@ -71,7 +71,7 @@ export async function getUserTasksForCurrentSprintByProjectId(
export async function getUserTasksHistory(projectId: number) {
const session = await auth();
const userId = session?.user?.id;
if (!userId) throw new Error("You must be signed in");
if (!userId) return "You must be signed in";

const sprintSurveys = await db
.select({ sprintSurvey: sprintSurvey, task: pipTask })
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function getUserTasksHistory(projectId: number) {
// TODO: inform the frontend when the survey is pending for processing

if (sprintSurveysWithTasks.length === 0) {
throw new Error("No task history available");
return "No task history available";
}

return sprintSurveysWithTasks;
Expand All @@ -119,18 +119,19 @@ export async function getUserTasksHistory(projectId: number) {
export async function getUserResourcesForCurrentSprint(projectId: number) {
const session = await auth();
const userId = session?.user?.id;
if (!userId) throw new Error("You must be signed in");
if (!userId) return "You must be signed in";

const currentSprintSurvey = await getCurrentSprintSurvey(projectId);
if (typeof currentSprintSurvey === "string") {
return currentSprintSurvey;
}

// check if the sprint is not processed to throw an error
// check if there's no sprint survey results throw an error
// check if all the surveys were answered, so the only one left is the project one

if (!currentSprintSurvey.processed) {
throw new Error(
"Curreny sprint survey was found, but it is not processed yet",
);
return "Curreny sprint survey was found, but it is not processed yet";
}

const res = await db
Expand All @@ -150,7 +151,7 @@ export async function getUserResourcesForCurrentSprint(projectId: number) {
const resources = res.map((e) => ({ ...e.resource }));

if (resources.length === 0) {
throw new Error("No resources available. Ask your manager for an update.");
return "No resources available. Ask your manager for an update.";
}

return resources;
Expand All @@ -159,7 +160,7 @@ export async function getUserResourcesForCurrentSprint(projectId: number) {
export async function getUserResourcesHistory(projectId: number) {
const session = await auth();
const userId = session?.user?.id;
if (!userId) throw new Error("You must be signed in");
if (!userId) return "You must be signed in";

const sprintSurveys = await db
.select({
Expand Down Expand Up @@ -202,7 +203,7 @@ export async function getUserResourcesHistory(projectId: number) {
// TODO: inform the frontend when the survey is pending for processing

if (sprintSurveysWithResources.length === 0) {
throw new Error("No resource history available");
return "No resource history available";
}

return sprintSurveysWithResources;
Expand Down

0 comments on commit 2d38dc1

Please sign in to comment.