hitbox for nav and standardizing api call format

This commit is contained in:
Martina 2020-11-27 17:30:40 -08:00
parent 579e879571
commit 396130ff64
5 changed files with 30 additions and 23 deletions

View File

@ -139,28 +139,28 @@ export const search = async (data) => {
export const createPendingFiles = async (data) => { export const createPendingFiles = async (data) => {
return await returnJSON(`/api/data/create-pending`, { return await returnJSON(`/api/data/create-pending`, {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,
body: JSON.stringify(data), body: JSON.stringify({ data }),
}); });
}; };
export const processPendingFiles = async (data) => { export const processPendingFiles = async () => {
return await returnJSON(`/api/data/process-pending`, { return await returnJSON(`/api/data/process-pending`, {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,
body: JSON.stringify(data), body: JSON.stringify(),
}); });
}; };
export const addFileToSlate = async (data) => { export const addFileToSlate = async (data) => {
return await returnJSON(`/api/slates/add-url`, { return await returnJSON(`/api/slates/add-url`, {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,
body: JSON.stringify(data), body: JSON.stringify({ data }),
}); });
}; };
export const updateViewer = async (data) => { export const updateViewer = async (data) => {
return await returnJSON(`/api/users/update`, { return await returnJSON(`/api/users/update`, {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,
body: JSON.stringify(data), body: JSON.stringify({ data }),
}); });
}; };

View File

@ -186,8 +186,12 @@ export default class ApplicationHeader extends React.Component {
return ( return (
<header css={STYLES_APPLICATION_HEADER}> <header css={STYLES_APPLICATION_HEADER}>
<div css={STYLES_LEFT}> <div css={STYLES_LEFT}>
<span css={STYLES_ICON_ELEMENT} style={{ position: "relative" }}> <span
<SVG.Menu height="24px" onClick={() => this._handleTogglePopup("nav")} /> css={STYLES_ICON_ELEMENT}
style={{ position: "relative" }}
onClick={() => this._handleTogglePopup("nav")}
>
<SVG.Menu height="24px" />
{this.state.popup === "nav" ? ( {this.state.popup === "nav" ? (
<Boundary <Boundary
captureResize={true} captureResize={true}

View File

@ -8,7 +8,7 @@ export default async (req, res) => {
return res.status(500).send({ decorator: "CREATE_PENDING_ERROR", error: true }); return res.status(500).send({ decorator: "CREATE_PENDING_ERROR", error: true });
} }
const response = await Data.createPendingData(req.body.data); const response = await Data.createPendingData(req.body.data.data);
if (!response) { if (!response) {
return res.status(404).send({ decorator: "CREATE_PENDING_ERROR", error: true }); return res.status(404).send({ decorator: "CREATE_PENDING_ERROR", error: true });

View File

@ -30,7 +30,7 @@ export default async (req, res) => {
}); });
} }
const slate = await Data.getSlateById({ id: req.body.slate.id }); const slate = await Data.getSlateById({ id: req.body.data.slate.id });
if (!slate) { if (!slate) {
return res.status(404).send({ return res.status(404).send({
@ -47,14 +47,14 @@ export default async (req, res) => {
} }
let newObjects = []; let newObjects = [];
if (Array.isArray(req.body.data)) { if (Array.isArray(req.body.data.data)) {
newObjects = [...req.body.data]; newObjects = [...req.body.data.data];
} else { } else {
newObjects = [req.body.data]; newObjects = [req.body.data.data];
} }
let slateURLs = slate.data.objects.map((file) => file.url); let slateURLs = slate.data.objects.map((file) => file.url);
let addlObjects; let addlObjects;
if (req.body.fromSlate) { if (req.body.data.fromSlate) {
let newURLs = []; let newURLs = [];
addlObjects = newObjects.filter((each) => { addlObjects = newObjects.filter((each) => {
if (slateURLs.includes(each.url) || newURLs.includes(each.url)) { if (slateURLs.includes(each.url) || newURLs.includes(each.url)) {
@ -100,7 +100,7 @@ export default async (req, res) => {
cid: cid, cid: cid,
size: each.size, size: each.size,
id: each.id, id: each.id,
ownerId: req.body.fromSlate ? each.ownerId : user.id, ownerId: req.body.data.fromSlate ? each.ownerId : user.id,
name: each.name, name: each.name,
title: each.title, title: each.title,
type: each.type, type: each.type,

View File

@ -28,9 +28,9 @@ export default async (req, res) => {
let unsafeResponse; let unsafeResponse;
if (req.body.username) { if (req.body.data.username) {
const existing = await Data.getUserByUsername({ const existing = await Data.getUserByUsername({
username: req.body.username.toLowerCase(), username: req.body.data.username.toLowerCase(),
}); });
if (existing && existing.id !== id) { if (existing && existing.id !== id) {
@ -38,7 +38,7 @@ export default async (req, res) => {
} }
} }
if (req.body.type === "SAVE_DEFAULT_ARCHIVE_CONFIG") { if (req.body.data.type === "SAVE_DEFAULT_ARCHIVE_CONFIG") {
let b; let b;
try { try {
b = await Utilities.getBucketAPIFromUserToken({ b = await Utilities.getBucketAPIFromUserToken({
@ -59,7 +59,10 @@ export default async (req, res) => {
} }
try { try {
const configResponse = await b.buckets.setDefaultArchiveConfig(b.bucketKey, req.body.config); const configResponse = await b.buckets.setDefaultArchiveConfig(
b.bucketKey,
req.body.data.config
);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
Social.sendTextileSlackMessage({ Social.sendTextileSlackMessage({
@ -74,14 +77,14 @@ export default async (req, res) => {
} }
} }
if (req.body.type == "CHANGE_PASSWORD") { if (req.body.data.type == "CHANGE_PASSWORD") {
if (!Validations.password(req.body.password)) { if (!Validations.password(req.body.data.password)) {
return res.status(500).send({ decorator: "SERVER_INVALID_PASSWORD", error: true }); return res.status(500).send({ decorator: "SERVER_INVALID_PASSWORD", error: true });
} }
const rounds = Number(Environment.LOCAL_PASSWORD_ROUNDS); const rounds = Number(Environment.LOCAL_PASSWORD_ROUNDS);
const salt = await BCrypt.genSalt(rounds); const salt = await BCrypt.genSalt(rounds);
const hash = await Utilities.encryptPassword(req.body.password, salt); const hash = await Utilities.encryptPassword(req.body.data.password, salt);
unsafeResponse = await Data.updateUserById({ unsafeResponse = await Data.updateUserById({
id: user.id, id: user.id,
@ -91,8 +94,8 @@ export default async (req, res) => {
} else { } else {
unsafeResponse = await Data.updateUserById({ unsafeResponse = await Data.updateUserById({
id: user.id, id: user.id,
username: req.body.username ? req.body.username.toLowerCase() : user.username, username: req.body.data.username ? req.body.data.username.toLowerCase() : user.username,
data: { ...user.data, ...req.body.data }, data: { ...user.data, ...req.body.data.data },
}); });
} }