mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-25 19:55:26 +03:00
feat(survey): change surveys table name to onboarding
This commit is contained in:
parent
095ccc63ab
commit
20ba244ce8
@ -521,8 +521,8 @@ export const getUserVersion = async (data) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const createSurvey = async (data) => {
|
||||
return await returnJSON(`/api/surveys/create`, {
|
||||
export const createOnboarding = async (data) => {
|
||||
return await returnJSON(`/api/onboarding/create`, {
|
||||
...DEFAULT_OPTIONS,
|
||||
body: JSON.stringify({ data }),
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ export const getById = (id, viewer) => {
|
||||
return { ...errorPage };
|
||||
}
|
||||
|
||||
if (viewer?.survey.onboarding === false) {
|
||||
if (viewer?.onboarding.survey === false) {
|
||||
return { ...surveyPage };
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ export const getById = (id, viewer) => {
|
||||
|
||||
export const getByHref = (href, viewer) => {
|
||||
let pathname;
|
||||
if (viewer?.surveys?.onboarding === false) {
|
||||
if (viewer?.onboarding?.survey === false) {
|
||||
return { page: { ...surveyPage } };
|
||||
}
|
||||
if (href) {
|
||||
|
@ -204,7 +204,7 @@ export default class ApplicationLayout extends React.Component {
|
||||
);
|
||||
}
|
||||
const isHeaderInView =
|
||||
this.props.page?.id === "NAV_SIGN_IN" || this.props.viewer?.surveys?.onboarding === false;
|
||||
this.props.page?.id === "NAV_SIGN_IN" || this.props.viewer?.onboarding?.survey === false;
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
|
@ -95,9 +95,9 @@ import getVerificationBySid from "~/node_common/data/methods/get-verification-by
|
||||
import pruneVerifications from "~/node_common/data/methods/prune-verifications";
|
||||
|
||||
// NOTE(amine):
|
||||
// Surveys postgres queries
|
||||
import createSurvey from "~/node_common/data/methods/create-survey";
|
||||
import getSurveyByUserId from "~/node_common/data/methods/get-survey-by-user-id";
|
||||
// Onboarding postgres queries
|
||||
import createOnboarding from "~/node_common/data/methods/create-onboarding";
|
||||
import getOnboardingByUserId from "~/node_common/data/methods/get-onboarding-by-user-id";
|
||||
|
||||
// NOTE(jim):
|
||||
// one-offs
|
||||
@ -190,7 +190,7 @@ export {
|
||||
updateTwitterToken,
|
||||
// NOTE(martina): Deals
|
||||
createDeal,
|
||||
// NOTE(amine): Surveys
|
||||
createSurvey,
|
||||
getSurveyByUserId,
|
||||
// NOTE(amine): Onboarding
|
||||
createOnboarding,
|
||||
getOnboardingByUserId,
|
||||
};
|
||||
|
@ -2,7 +2,7 @@ import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async ({ userId, prevTools, usecases, referrals }) => {
|
||||
return await runQuery({
|
||||
label: "CREATE_SURVEY",
|
||||
label: "CREATE_ONBOARDING",
|
||||
queryFn: async (DB) => {
|
||||
let query = await DB.insert({
|
||||
userId,
|
||||
@ -10,7 +10,7 @@ export default async ({ userId, prevTools, usecases, referrals }) => {
|
||||
usecases,
|
||||
referrals,
|
||||
})
|
||||
.into("surveys")
|
||||
.into("onboarding")
|
||||
.returning("*");
|
||||
|
||||
if (!query) {
|
||||
@ -24,7 +24,7 @@ export default async ({ userId, prevTools, usecases, referrals }) => {
|
||||
errorFn: async () => {
|
||||
return {
|
||||
error: true,
|
||||
decorator: "CREATE_SURVEY",
|
||||
decorator: "CREATE_ONBOARDING",
|
||||
};
|
||||
},
|
||||
});
|
@ -37,7 +37,7 @@ export default async ({ id }) => {
|
||||
|
||||
const usage = await DB.from("usage").where({ userId: id }).del();
|
||||
|
||||
const surveys = await DB.from("surveys").where({ userId: id }).del();
|
||||
const onboarding = await DB.from("onboarding").where({ userId: id }).del();
|
||||
|
||||
const data = await DB.from("users").where({ id }).del().returning("*");
|
||||
|
||||
|
@ -2,9 +2,10 @@ import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async ({ userId }) => {
|
||||
return await runQuery({
|
||||
label: "GET_SURVEY_BY_USER_ID",
|
||||
label: "GET_ONBOARDING_BY_USER_ID",
|
||||
queryFn: async (DB) => {
|
||||
let query = await DB.select("*").from("surveys").where({ userId });
|
||||
let query = await DB.select("*").from("onboarding").where({ userId });
|
||||
console.log(query);
|
||||
|
||||
if (!query || query.error) {
|
||||
return null;
|
||||
@ -18,7 +19,7 @@ export default async ({ userId }) => {
|
||||
errorFn: async () => {
|
||||
return {
|
||||
error: true,
|
||||
decorator: "GET_SURVEY_BY_USER_ID",
|
||||
decorator: "GET_ONBOARDING_BY_USER_ID",
|
||||
};
|
||||
},
|
||||
});
|
@ -42,7 +42,7 @@ const websocketSend = async (type, data) => {
|
||||
|
||||
export const hydratePartial = async (
|
||||
id,
|
||||
{ viewer, slates, keys, library, subscriptions, following, followers, surveys }
|
||||
{ viewer, slates, keys, library, subscriptions, following, followers, onboarding }
|
||||
) => {
|
||||
if (!id) return;
|
||||
|
||||
@ -102,8 +102,13 @@ export const hydratePartial = async (
|
||||
const followers = await Data.getFollowersByUserId({ userId: id });
|
||||
update.followers = followers;
|
||||
}
|
||||
if (surveys) {
|
||||
update.surveys = { onboarding: true };
|
||||
if (onboarding) {
|
||||
const onboarding = await Data.getOnboardingByUserId({ userId: id });
|
||||
update.onboarding = {
|
||||
upload: onboarding?.upload,
|
||||
tags: onboarding?.tags,
|
||||
survey: !!onboarding?.userId,
|
||||
};
|
||||
}
|
||||
|
||||
websocketSend("UPDATE", update);
|
||||
@ -152,20 +157,26 @@ export const getById = async ({ id }) => {
|
||||
|
||||
// user.library = await Data.getFilesByUserId({ id });
|
||||
|
||||
const [slates, keys, subscriptions, following, followers, surveyResponse] = (
|
||||
const [slates, keys, subscriptions, following, followers, onboardingResponse] = (
|
||||
await Promise.allSettled([
|
||||
Data.getSlatesByUserId({ ownerId: id, includeFiles: true }),
|
||||
Data.getAPIKeysByUserId({ userId: id }),
|
||||
Data.getSubscriptionsByUserId({ ownerId: id }),
|
||||
Data.getFollowingByUserId({ ownerId: id }),
|
||||
Data.getFollowersByUserId({ userId: id }),
|
||||
Data.getSurveyByUserId({ userId: id }),
|
||||
Data.getOnboardingByUserId({ userId: id }),
|
||||
])
|
||||
).map((item) => item.value);
|
||||
|
||||
const libraryCids =
|
||||
user?.library?.reduce((acc, file) => ({ ...acc, [file.cid]: true }), {}) || {};
|
||||
|
||||
const onboarding = {
|
||||
upload: onboardingResponse?.upload,
|
||||
tags: onboardingResponse?.tags,
|
||||
survey: !!onboardingResponse?.userId,
|
||||
};
|
||||
|
||||
let cids = {};
|
||||
let bytes = 0;
|
||||
let imageBytes = 0;
|
||||
@ -229,9 +240,7 @@ export const getById = async ({ id }) => {
|
||||
following,
|
||||
followers,
|
||||
libraryCids,
|
||||
surveys: {
|
||||
onboarding: onboardingSurvey,
|
||||
},
|
||||
onboarding,
|
||||
};
|
||||
|
||||
return viewer;
|
||||
|
@ -6,12 +6,14 @@ import * as Environment from "~/node_common/environment";
|
||||
|
||||
export default async (req, res) => {
|
||||
if (!Strings.isEmpty(Environment.ALLOWED_HOST) && req.headers.host !== Environment.ALLOWED_HOST) {
|
||||
return res.status(403).send({ decorator: "SERVER_CREATE_SURVEY_NOT_ALLOWED", error: true });
|
||||
return res.status(403).send({ decorator: "SERVER_CREATE_ONBOARDING_NOT_ALLOWED", error: true });
|
||||
}
|
||||
|
||||
const { tools, referrals, useCases } = req?.body?.data;
|
||||
if (!tools || !referrals || !useCases) {
|
||||
return res.status(403).send({ decorator: "SERVER_CREATE_SURVEY_INVALID_DATA", error: true });
|
||||
return res
|
||||
.status(403)
|
||||
.send({ decorator: "SERVER_CREATE_ONBOARDING_INVALID_DATA", error: true });
|
||||
}
|
||||
|
||||
const userInfo = await RequestUtilities.checkAuthorizationInternal(req, res);
|
||||
@ -20,22 +22,22 @@ export default async (req, res) => {
|
||||
}
|
||||
const { id } = userInfo;
|
||||
|
||||
const survey = Data.createSurvey({
|
||||
const onboarding = Data.createOnboarding({
|
||||
userId: id,
|
||||
prevTools: tools,
|
||||
usecases: useCases,
|
||||
referrals,
|
||||
});
|
||||
|
||||
if (!survey) {
|
||||
return res.status(404).send({ decorator: "SERVER_CREATE_SURVEY_FAILED", error: true });
|
||||
if (!onboarding) {
|
||||
return res.status(404).send({ decorator: "SERVER_CREATE_ONBOARDING_FAILED", error: true });
|
||||
}
|
||||
|
||||
if (survey.error) {
|
||||
return res.status(500).send({ decorator: "SERVER_CREATE_SURVEY_FAILED", error: true });
|
||||
if (onboarding.error) {
|
||||
return res.status(500).send({ decorator: "SERVER_CREATE_ONBOARDING_FAILED", error: true });
|
||||
}
|
||||
|
||||
await ViewerManager.hydratePartial(id, { surveys: true });
|
||||
await ViewerManager.hydratePartial(id, { onboarding: true });
|
||||
|
||||
return res.status(200).send({ decorator: "SERVER_CREATE_SURVEY_SUCCESS" });
|
||||
return res.status(200).send({ decorator: "SERVER_CREATE_ONBOARDING_SUCCESS" });
|
||||
};
|
@ -128,7 +128,7 @@ function SceneSurvey() {
|
||||
.map((item) => REFERRAL_OPTIONS[item] || item)
|
||||
.join(",");
|
||||
// call endpoint
|
||||
const response = await Actions.createSurvey(surveyResults.current);
|
||||
const response = await Actions.createOnboarding(surveyResults.current);
|
||||
if (Events.hasError(response)) {
|
||||
return;
|
||||
}
|
||||
|
@ -181,12 +181,14 @@ const createTwitterTokensTable = db.schema.createTable("twitterTokens", function
|
||||
table.string("verified").nullable();
|
||||
});
|
||||
|
||||
const createSurveysTable = db.schema.createTable("surveys", function (table) {
|
||||
const createOnboardingTable = db.schema.createTable("onboarding", function (table) {
|
||||
table.uuid("id").primary().unique().notNullable().defaultTo(db.raw("uuid_generate_v4()"));
|
||||
table.uuid("userId").references("id").inTable("users");
|
||||
table.string("prevTools").notNullable();
|
||||
table.string("usecases").notNullable();
|
||||
table.string("referrals").notNullable();
|
||||
table.boolean("upload").defaultTo(false);
|
||||
table.boolean("tags").defaultTo(false);
|
||||
});
|
||||
|
||||
// --------------------------
|
||||
@ -208,7 +210,7 @@ Promise.all([
|
||||
createGlobalTable,
|
||||
createUsageTable,
|
||||
createTwitterTokensTable,
|
||||
createSurveysTable,
|
||||
createOnboardingTable,
|
||||
]);
|
||||
|
||||
Logging.log(`FINISHED: seed-database.js`);
|
||||
|
Loading…
Reference in New Issue
Block a user