Skip to content

Commit

Permalink
date format changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakhar-commits committed Nov 21, 2023
1 parent ee3ea76 commit 19c6767
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/pages/SessionCreator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export default function SessionCreator() {
});

const createSession = async () => {
console.log(data);

await postFormData(data);
setIsSessionAdded(true);

Expand Down
25 changes: 19 additions & 6 deletions src/utils/FormInputHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@ async function getData(currentPage: number, limit: number) {
};
}

function formatDateTime(date: string, time: string) {
const [year, month, day] = date.split("-").map(Number);
const [hour, minute] = time.split(":").map(Number);

const combinedDate = new Date(year, month - 1, day, hour, minute);
console.log(combinedDate);

return combinedDate;
}
// post data to the server
async function postFormData(formData: RowType) {
const { student, test, timeline, dateCreated } = formData;
let start_time = timeline.startDate + "T" + timeline.startTime + ":00";
let end_time = timeline.endDate + "T" + timeline.endTime + ":00";
console.log(timeline);

let start_time = formatDateTime(timeline.startDate, timeline.startTime);
let end_time = formatDateTime(timeline.endDate, timeline.endTime);
console.log(start_time);

const requestBody = {
name: test.name,
platform: test.platform,
platform_link: test.platformLink,
portal_link: test.portalLink,
portal_link: "", //responds to the portal link
start_time,
end_time,
is_active: "",
Expand Down Expand Up @@ -53,9 +66,9 @@ async function postFormData(formData: RowType) {
test_purpose: test.purpose,
enabled: timeline.isEnabled,
infinite_session: true,
cms_test_id: test.cmdId,
cms_test_id: test.cmsId,
test_takers_count: test.testTakers,
has_synced_to_bq: true,
has_synced_to_bq: false,
optional_limits: test.optionalLimit,
marking_scheme: test.markingScheme,
test_type: test.type,
Expand All @@ -68,7 +81,7 @@ async function postFormData(formData: RowType) {

try {
const response = await instance.post(
"https://staging-db.avantifellows.org/api/session",
`${process.env.NEXT_PUBLIC_DB_URL}/api/session`,
requestBody
);
return response.data;
Expand Down

0 comments on commit 19c6767

Please sign in to comment.