add mutation to set item explicitly body specific

now that Support feature works!
This commit is contained in:
Emi Matchu 2020-08-14 22:01:27 -07:00
parent b23f64ad53
commit 380cbf543b

View file

@ -207,6 +207,12 @@ const typeDefs = gql`
supportSecret: String! supportSecret: String!
): Item! ): Item!
setItemExplicitlyBodySpecific(
itemId: ID!
explicitlyBodySpecific: Boolean!
supportSecret: String!
): Item!
setLayerBodyId( setLayerBodyId(
layerId: ID! layerId: ID!
bodyId: ID! bodyId: ID!
@ -579,6 +585,31 @@ const resolvers = {
return { id: itemId }; return { id: itemId };
}, },
setItemExplicitlyBodySpecific: async (
_,
{ itemId, explicitlyBodySpecific, supportSecret },
{ db }
) => {
if (supportSecret !== process.env["SUPPORT_SECRET"]) {
throw new Error(`Support secret is incorrect. Try setting up again?`);
}
const [
result,
] = await db.execute(
`UPDATE items SET explicitly_body_specific = ? WHERE id = ? LIMIT 1`,
[explicitlyBodySpecific ? 1 : 0, itemId]
);
if (result.affectedRows !== 1) {
throw new Error(
`Expected to affect 1 item, but affected ${result.affectedRows}`
);
}
return { id: itemId };
},
setLayerBodyId: async (_, { layerId, bodyId, supportSecret }, { db }) => { setLayerBodyId: async (_, { layerId, bodyId, supportSecret }, { db }) => {
if (supportSecret !== process.env["SUPPORT_SECRET"]) { if (supportSecret !== process.env["SUPPORT_SECRET"]) {
throw new Error(`Support secret is incorrect. Try setting up again?`); throw new Error(`Support secret is incorrect. Try setting up again?`);