Added basic creation of shops.
This commit is contained in:
@@ -44929,6 +44929,27 @@
|
|||||||
<folder_node>
|
<folder_node>
|
||||||
<name>signinerror</name>
|
<name>signinerror</name>
|
||||||
<children>
|
<children>
|
||||||
|
<concept_node>
|
||||||
|
<name>auth/user-disabled</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
<concept_node>
|
<concept_node>
|
||||||
<name>auth/user-not-found</name>
|
<name>auth/user-not-found</name>
|
||||||
<definition_loaded>false</definition_loaded>
|
<definition_loaded>false</definition_loaded>
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export const uploadToCloudinary = async (
|
|||||||
//Set variables for getting the signed URL.
|
//Set variables for getting the signed URL.
|
||||||
let timestamp = Math.floor(Date.now() / 1000);
|
let timestamp = Math.floor(Date.now() / 1000);
|
||||||
let public_id = key;
|
let public_id = key;
|
||||||
let tags = `${bodyshop.textid},${
|
let tags = `${bodyshop.imexshopid},${
|
||||||
tagsArray ? tagsArray.map((tag) => `${tag},`) : ""
|
tagsArray ? tagsArray.map((tag) => `${tag},`) : ""
|
||||||
}`;
|
}`;
|
||||||
// let eager = process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS;
|
// let eager = process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS;
|
||||||
|
|||||||
@@ -2668,6 +2668,7 @@
|
|||||||
"users": {
|
"users": {
|
||||||
"errors": {
|
"errors": {
|
||||||
"signinerror": {
|
"signinerror": {
|
||||||
|
"auth/user-disabled": "User account disabled. ",
|
||||||
"auth/user-not-found": "A user with this email does not exist.",
|
"auth/user-not-found": "A user with this email does not exist.",
|
||||||
"auth/wrong-password": "The email and password combination you provided is incorrect."
|
"auth/wrong-password": "The email and password combination you provided is incorrect."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2668,6 +2668,7 @@
|
|||||||
"users": {
|
"users": {
|
||||||
"errors": {
|
"errors": {
|
||||||
"signinerror": {
|
"signinerror": {
|
||||||
|
"auth/user-disabled": "",
|
||||||
"auth/user-not-found": "",
|
"auth/user-not-found": "",
|
||||||
"auth/wrong-password": ""
|
"auth/wrong-password": ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2668,6 +2668,7 @@
|
|||||||
"users": {
|
"users": {
|
||||||
"errors": {
|
"errors": {
|
||||||
"signinerror": {
|
"signinerror": {
|
||||||
|
"auth/user-disabled": "",
|
||||||
"auth/user-not-found": "",
|
"auth/user-not-found": "",
|
||||||
"auth/wrong-password": ""
|
"auth/wrong-password": ""
|
||||||
}
|
}
|
||||||
|
|||||||
14
server.js
14
server.js
@@ -157,7 +157,21 @@ app.post(
|
|||||||
fb.unsubscribe
|
fb.unsubscribe
|
||||||
);
|
);
|
||||||
app.post("/adm/updateuser", fb.validateFirebaseIdToken, fb.updateUser);
|
app.post("/adm/updateuser", fb.validateFirebaseIdToken, fb.updateUser);
|
||||||
|
app.post("/adm/getuser", fb.validateFirebaseIdToken, fb.getUser);
|
||||||
app.post("/adm/createuser", fb.validateFirebaseIdToken, fb.createUser);
|
app.post("/adm/createuser", fb.validateFirebaseIdToken, fb.createUser);
|
||||||
|
const adm = require("./server/admin/adminops");
|
||||||
|
app.post(
|
||||||
|
"/adm/createassociation",
|
||||||
|
fb.validateFirebaseIdToken,
|
||||||
|
fb.validateAdmin,
|
||||||
|
adm.createAssociation
|
||||||
|
);
|
||||||
|
app.post(
|
||||||
|
"/adm/createshop",
|
||||||
|
fb.validateFirebaseIdToken,
|
||||||
|
fb.validateAdmin,
|
||||||
|
adm.createShop
|
||||||
|
);
|
||||||
|
|
||||||
//Stripe Processing
|
//Stripe Processing
|
||||||
var stripe = require("./server/stripe/payment");
|
var stripe = require("./server/stripe/payment");
|
||||||
|
|||||||
68
server/admin/adminops.js
Normal file
68
server/admin/adminops.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const _ = require("lodash");
|
||||||
|
const logger = require("../utils/logger");
|
||||||
|
require("dotenv").config({
|
||||||
|
path: path.resolve(
|
||||||
|
process.cwd(),
|
||||||
|
`.env.${process.env.NODE_ENV || "development"}`
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = require("../graphql-client/graphql-client").client;
|
||||||
|
|
||||||
|
exports.createAssociation = async (req, res) => {
|
||||||
|
logger.log("admin-create-association", "ADMIN", req.user.email, null, {
|
||||||
|
request: req.body,
|
||||||
|
ioadmin: true,
|
||||||
|
});
|
||||||
|
const { shopid, authlevel, useremail } = req.body;
|
||||||
|
|
||||||
|
const result = await client.request(
|
||||||
|
`mutation INSERT_ASSOCIATION($assoc: associations_insert_input!){
|
||||||
|
insert_associations_one(object:$assoc){
|
||||||
|
id
|
||||||
|
authlevel
|
||||||
|
useremail
|
||||||
|
active
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
{
|
||||||
|
assoc: { shopid, authlevel, useremail, active: false },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
res.json(result);
|
||||||
|
};
|
||||||
|
exports.createShop = async (req, res) => {
|
||||||
|
logger.log("admin-create-shop", "ADMIN", req.user.email, null, {
|
||||||
|
request: req.body,
|
||||||
|
ioadmin: true,
|
||||||
|
});
|
||||||
|
const { bodyshop, ronum } = req.body;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await client.request(
|
||||||
|
`mutation INSERT_BODYSHOPS($bs: bodyshops_insert_input!){
|
||||||
|
insert_bodyshops_one(object:$bs){
|
||||||
|
id
|
||||||
|
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
{
|
||||||
|
bs: {
|
||||||
|
...bodyshop,
|
||||||
|
counters: {
|
||||||
|
data: [
|
||||||
|
{ countertype: "ronum", count: ronum },
|
||||||
|
{ countertype: "ihbnum", count: 1 },
|
||||||
|
{ countertype: "paymentnum", count: 1 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
res.json(result);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
var admin = require("firebase-admin");
|
var admin = require("firebase-admin");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const { auth } = require("firebase-admin");
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
path: path.resolve(
|
path: path.resolve(
|
||||||
process.cwd(),
|
process.cwd(),
|
||||||
`.env.${process.env.NODE_ENV || "development"}`
|
`.env.${process.env.NODE_ENV || "development"}`
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
const client = require("../graphql-client/graphql-client").client;
|
||||||
var serviceAccount = require(process.env.FIREBASE_ADMINSDK_JSON);
|
var serviceAccount = require(process.env.FIREBASE_ADMINSDK_JSON);
|
||||||
|
|
||||||
admin.initializeApp({
|
admin.initializeApp({
|
||||||
@@ -19,54 +20,61 @@ exports.admin = admin;
|
|||||||
|
|
||||||
const adminEmail = [
|
const adminEmail = [
|
||||||
"patrick@imex.dev",
|
"patrick@imex.dev",
|
||||||
"patrick@imex.text",
|
//"patrick@imex.test",
|
||||||
"patrick@imex.prod",
|
"patrick@imex.prod",
|
||||||
"patrick@imexsystems.ca",
|
"patrick@imexsystems.ca",
|
||||||
"patrick@thinkimex.com",
|
"patrick@thinkimex.com",
|
||||||
];
|
];
|
||||||
|
|
||||||
exports.createUser = (req, res) => {
|
exports.createUser = async (req, res) => {
|
||||||
logger.log("admin-create-user", "WARN", req.user.email, null, {
|
logger.log("admin-create-user", "ADMIN", req.user.email, null, {
|
||||||
request: req.body,
|
request: req.body,
|
||||||
|
ioadmin: true,
|
||||||
});
|
});
|
||||||
if (!adminEmail.includes(req.user.email)) {
|
|
||||||
logger.log(
|
const { email, displayName, password, shopid, authlevel } = req.body;
|
||||||
"admin-create-user-unauthorized",
|
try {
|
||||||
"ERROR",
|
const userRecord = await admin
|
||||||
req.user.email,
|
.auth()
|
||||||
null,
|
.createUser({ email, displayName, password });
|
||||||
|
|
||||||
|
// See the UserRecord reference doc for the contents of userRecord.
|
||||||
|
|
||||||
|
const result = await client.request(
|
||||||
|
`
|
||||||
|
mutation INSERT_USER($user: users_insert_input!) {
|
||||||
|
insert_users_one(object: $user) {
|
||||||
|
email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
{
|
{
|
||||||
request: req.body,
|
user: {
|
||||||
user: req.user,
|
email,
|
||||||
|
authid: userRecord.uid,
|
||||||
|
associations: {
|
||||||
|
data: [{ shopid, authlevel, active: true }],
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
res.sendStatus(404);
|
|
||||||
}
|
|
||||||
const { email, displayName, password } = req.body;
|
|
||||||
admin
|
|
||||||
.auth()
|
|
||||||
.createUser({ email, displayName, password })
|
|
||||||
.then((userRecord) => {
|
|
||||||
// See the UserRecord reference doc for the contents of userRecord.
|
|
||||||
|
|
||||||
logger.log("admin-update-user-success", "DEBUG", req.user.email, null, {
|
res.json({ userRecord, result });
|
||||||
userRecord,
|
} catch (error) {
|
||||||
});
|
logger.log("admin-update-user-error", "ERROR", req.user.email, null, {
|
||||||
res.json(userRecord);
|
error,
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
logger.log("admin-update-user-error", "ERROR", req.user.email, null, {
|
|
||||||
error,
|
|
||||||
});
|
|
||||||
res.status(500).json(error);
|
|
||||||
});
|
});
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.updateUser = (req, res) => {
|
exports.updateUser = (req, res) => {
|
||||||
logger.log("admin-update-user", "WARN", req.user.email, null, {
|
logger.log("admin-update-user", "ADMIN", req.user.email, null, {
|
||||||
request: req.body,
|
request: req.body,
|
||||||
|
ioadmin: true,
|
||||||
});
|
});
|
||||||
if (!adminEmail.includes(req.user.email)) {
|
|
||||||
|
if (!adminEmail.includes(req.user.email) && !req.user.ioadmin) {
|
||||||
logger.log(
|
logger.log(
|
||||||
"admin-update-user-unauthorized",
|
"admin-update-user-unauthorized",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
@@ -78,6 +86,7 @@ exports.updateUser = (req, res) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
admin
|
admin
|
||||||
@@ -98,8 +107,9 @@ exports.updateUser = (req, res) => {
|
|||||||
.then((userRecord) => {
|
.then((userRecord) => {
|
||||||
// See the UserRecord reference doc for the contents of userRecord.
|
// See the UserRecord reference doc for the contents of userRecord.
|
||||||
|
|
||||||
logger.log("admin-update-user-success", "DEBUG", req.user.email, null, {
|
logger.log("admin-update-user-success", "ADMIN", req.user.email, null, {
|
||||||
userRecord,
|
userRecord,
|
||||||
|
ioadmin: true,
|
||||||
});
|
});
|
||||||
res.json(userRecord);
|
res.json(userRecord);
|
||||||
})
|
})
|
||||||
@@ -111,6 +121,41 @@ exports.updateUser = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getUser = (req, res) => {
|
||||||
|
logger.log("admin-get-user", "ADMIN", req.user.email, null, {
|
||||||
|
request: req.body,
|
||||||
|
ioadmin: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!adminEmail.includes(req.user.email) && !req.user.ioadmin) {
|
||||||
|
logger.log(
|
||||||
|
"admin-update-user-unauthorized",
|
||||||
|
"ERROR",
|
||||||
|
req.user.email,
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
request: req.body,
|
||||||
|
user: req.user,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
res.sendStatus(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
admin
|
||||||
|
.auth()
|
||||||
|
.getUser(req.body.uid)
|
||||||
|
.then((userRecord) => {
|
||||||
|
res.json(userRecord);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
logger.log("admin-get-user-error", "ERROR", req.user.email, null, {
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
res.status(500).json(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.sendNotification = async (req, res) => {
|
exports.sendNotification = async (req, res) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Send a message to the device corresponding to the provided
|
// Send a message to the device corresponding to the provided
|
||||||
@@ -221,3 +266,35 @@ exports.validateFirebaseIdToken = async (req, res, next) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.validateAdmin = async (req, res, next) => {
|
||||||
|
if (!adminEmail.includes(req.user.email) && !req.user.ioadmin) {
|
||||||
|
logger.log("admin-validation-failed", "ERROR", req.user.email, null, {
|
||||||
|
request: req.body,
|
||||||
|
user: req.user,
|
||||||
|
});
|
||||||
|
res.sendStatus(404);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//Admin claims code.
|
||||||
|
// const uid = "JEqqYlsadwPEXIiyRBR55fflfko1";
|
||||||
|
|
||||||
|
// admin
|
||||||
|
// .auth()
|
||||||
|
// .getUser(uid)
|
||||||
|
// .then((user) => {
|
||||||
|
// console.log(user);
|
||||||
|
// admin.auth().setCustomUserClaims(uid, {
|
||||||
|
// ioadmin: true,
|
||||||
|
// "https://hasura.io/jwt/claims": {
|
||||||
|
// "x-hasura-default-role": "admin",
|
||||||
|
// "x-hasura-allowed-roles": ["admin"],
|
||||||
|
// "x-hasura-user-id": uid,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function log(message, type, user, record, object) {
|
|||||||
record,
|
record,
|
||||||
...object,
|
...object,
|
||||||
});
|
});
|
||||||
logger.log(message, {
|
logger.log(message, message, {
|
||||||
type,
|
type,
|
||||||
env: process.env.NODE_ENV || "development",
|
env: process.env.NODE_ENV || "development",
|
||||||
user,
|
user,
|
||||||
|
|||||||
Reference in New Issue
Block a user