Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sunfee planday #49

Merged
merged 11 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files.trimTrailingWhitespace": true,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"[prisma]": {
"editor.formatOnSave": true
Expand Down
151 changes: 151 additions & 0 deletions api/src/functions/rolloverPreviousTasks/rolloverPreviousTasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { logger } from 'src/lib/logger'
import {authDecoder} from "@redwoodjs/auth-dbauth-api";
import {getCurrentUser} from "src/lib/auth";
import {db} from 'src/lib/db';
/**
* The handler function is your code that processes http request events.
* You can use return and throw to send a response or error, respectively.
*
* Important: When deployed, a custom serverless function is an open API endpoint and
* is your responsibility to secure appropriately.
*
* @see {@link https://redwoodjs.com/docs/serverless-functions#security-considerations|Serverless Function Considerations}
* in the RedwoodJS documentation for more information.
*
* @typedef { import('aws-lambda').APIGatewayEvent } APIGatewayEvent
* @typedef { import('aws-lambda').Context } Context
* @param { APIGatewayEvent } event - an object which contains information from the invoker.
* @param { Context } context - contains information about the invocation,
* function, and execution environment.
*/


export const handler = async (event, _context) => {
logger.info(`${event.httpMethod} ${event.path}: rolloverPreviousTasks function`)

// Get the current user
const { userId, date } = event.queryStringParameters
const dd= new Date(date)

const most_recent_tasks = await db.task.findFirst({
where: {
userId: parseInt(userId),
NOT: {
taskList: {equals: {"Other":[],"Important":[],"Top Priority":[]}}
},
date: {
lt: dd
}
},
orderBy: [
{date: 'desc'}
],
select: {
taskList: true,
date: true,
id: true
},
})

const updated_tasks = JSON.parse(JSON.stringify(most_recent_tasks.taskList));
for (let type of ["Top Priority", "Important", "Other"]) {
for (let i = 0; i < updated_tasks[type].length; i++) {
if (updated_tasks[type][i].status === "InProgress") {
updated_tasks[type][i].status = "Rollover"
}
}
}

let rolled_over = JSON.parse(JSON.stringify(most_recent_tasks.taskList));
for (let type of ["Top Priority", "Important", "Other"]) {
for (let i = rolled_over[type].length - 1; i >= 0; i--) {
if (rolled_over[type][i].status === "Completed" || rolled_over[type][i].status === "Cancelled") {
rolled_over[type].splice(i, 1);
} else {
rolled_over[type][i].status = "NotStarted"
rolled_over[type][i].pomodorosComplete = 0
}
}
}

const new_tasks_list = {"Top Priority": [], "Important": [], "Other": []}
let top_three = [];
for (let type of ["Top Priority", "Important", "Other"]) {
for (let i = 0; i < rolled_over[type].length; i++) {
top_three.push(rolled_over[type][i])
if (top_three.length >= 3) break;
}
if (top_three.length >= 3) break;
}

let remaining_important = [];
let skip = top_three.length;
for (let type of ["Top Priority", "Important", "Other"]) {
for (let i = 0; i < rolled_over[type].length; i++) {
if (skip <= 0 && type === "Important") {
remaining_important.push(rolled_over[type][i])
}
skip--;
}
}

let new_other = [];
if (!remaining_important.length) {
remaining_important = rolled_over["Other"]
} else {
new_other = rolled_over["Other"]
}

new_tasks_list["Top Priority"] = top_three;
new_tasks_list["Important"] = remaining_important;
new_tasks_list["Other"] = new_other;

await db.task.update({
where: {id: most_recent_tasks.id},
data: {
taskList: updated_tasks
}
})

await db.task.update({
where: {userId_date: {userId: parseInt(userId), date: dd}},
data: {
taskList: new_tasks_list
}
})


// //var olTasks = oldTasks(allTasks, dd)/*
// const vr = currentUser.tasks[1].taskList["Other"][0]
// vr.status="Rollover"
//
// let arr={
// ["Top Priority"]:[],
// Important:[],
// Other:[]
//
// }
// arr['Top Priority'].push(vr)
// //let rv=vr
// //const f = vr.Other.length*/

// return {
// statusCode: 200,
// headers: {
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify({
// data: 'rolloverPreviousTasks function',
// updated_tasks,
// new_tasks_list
// }),
// }

return {
statusCode: 302,
headers: {
Location: '/',
},
error: 'Planned day'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const standard = defineScenario({
// Define the "fixture" to write into your test database here
// See guide: https://redwoodjs.com/docs/testing#scenarios
})
1 change: 1 addition & 0 deletions api/src/graphql/users.sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const schema = gql`
longBreak: Int!
picture: String!
identities: [Identity]!
tasks: [Task]!
}

type Query {
Expand Down
3 changes: 2 additions & 1 deletion api/src/lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const getCurrentUser = async (session) => {
shortBreak: true,
longBreak: true,
picture: true,
identities: true},
identities: true,
tasks:true},
});

if (user === null) {
Expand Down
31 changes: 27 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/src/layouts/MainLayout/MainLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const MainLayout = ({ children }) => {
<Image mt={"10vh"} src={"img/pending.png"} />
<Box hidden={title === 'Profile'|| (date2 && moment(date2, 'YYYY-MM-DD').isBefore(moment(), 'day'))}>
<Text textAlign={"center"} fontSize={20} fontFamily={"DM Sans"} fontWeight={"700"}>It's time to plan your day!</Text>
<Button colorScheme={"white"} variant={"outline"} w={"100%"} pt={7} pb={7} href={`/.netlify/functions/todaysCalendar?userId=${currentUser?.id}`} as={'a'}>Plan Day</Button>
<Button colorScheme={"white"} variant={"outline"} w={"100%"} pt={7} pb={7} href={`/.netlify/functions/rolloverPreviousTasks?userId=${currentUser?.id}&date=2023-12-19`} as={'a'}>Plan Day</Button>
</Box>
<Spacer />
<Button colorScheme={"white"} variant={"outline"} type='button' onClick={logOut} mb={'5vh'}><LogoutIcon />Logout</Button>
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/HomePage/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const HomePage = ({setDate2}) => {
return (<>
<MetaTags title="Home" description="Home page"/>
<DatePicker setDateProp={setDate}/>

<Flex fontFamily={'DM Sans'} gap={'16px'} mt={'20px'}>
<Box w={"55%"}>
<Text fontSize={'30px'} fontWeight={'700'}>
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5488,7 +5488,19 @@ __metadata:
languageName: node
linkType: hard

"@prisma/client@latest, @prisma/client@npm:5.7.0":
"@prisma/client@latest":
version: 5.7.1
resolution: "@prisma/client@npm:5.7.1"
peerDependencies:
prisma: "*"
peerDependenciesMeta:
prisma:
optional: true
checksum: 5eafbe3955de13620c7b661282c79e85211bb0cba950559f87e7a679ff06f5242864b0cbe6e76316eb35366ac3df9b2b02ced7cbedc238bcbc4e412d7acf3b72
languageName: node
linkType: hard

"@prisma/client@npm:5.7.0":
version: 5.7.0
resolution: "@prisma/client@npm:5.7.0"
peerDependencies:
Expand Down