mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
Merge branch 'staging' of https://github.com/OpenSignLabs/OpenSign into raktima-opensignlabs-patch-11
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -17,15 +17,8 @@ const AddTeam = (props) => {
|
||||
const getTeamList = async () => {
|
||||
setIsLoader(true);
|
||||
try {
|
||||
const extUser = JSON.parse(localStorage.getItem("Extand_Class"))?.[0];
|
||||
const teamCls = new Parse.Query("contracts_Teams");
|
||||
teamCls.equalTo("OrganizationId", {
|
||||
__type: "Pointer",
|
||||
className: "contracts_Organizations",
|
||||
objectId: extUser.OrganizationId.objectId
|
||||
});
|
||||
teamCls.equalTo("IsActive", true);
|
||||
const teamRes = await teamCls.find();
|
||||
const teams = await Parse.Cloud.run("getteams");
|
||||
const teamRes = JSON.parse(JSON.stringify(teams));
|
||||
if (teamRes.length > 0) {
|
||||
const _teamRes = JSON.parse(JSON.stringify(teamRes));
|
||||
const allUsersteam = _teamRes.find((x) => x.Name === "All Users");
|
||||
@@ -73,76 +66,47 @@ const AddTeam = (props) => {
|
||||
}
|
||||
}
|
||||
try {
|
||||
const localUser = JSON.parse(localStorage.getItem("Extand_Class"))?.[0];
|
||||
setIsLoader(true);
|
||||
const team = new Parse.Query("contracts_Teams");
|
||||
team.equalTo("Name", formdata.name);
|
||||
let data = { Name: formdata.name };
|
||||
if (updatedAncestors.length > 0) {
|
||||
const ParentId = updatedAncestors[updatedAncestors.length - 1];
|
||||
team.equalTo("ParentId", ParentId);
|
||||
data["ParentId"] = ParentId?.objectId;
|
||||
data["Ancestors"] = updatedAncestors;
|
||||
}
|
||||
if (localUser && localUser.OrganizationId) {
|
||||
team.equalTo("OrganizationId", {
|
||||
__type: "Pointer",
|
||||
className: "contracts_Organizations",
|
||||
objectId: localUser.OrganizationId.objectId
|
||||
const newTeamRes = await Parse.Cloud.run("addteam", data);
|
||||
// console.log("teamRes ", newTeamRes);
|
||||
if (updatedAncestors.length > 0) {
|
||||
const ParentId = teamList.find((x) => x.objectId === formdata.team);
|
||||
props.handleTeamInfo({
|
||||
objectId: newTeamRes.id,
|
||||
Name: formdata.name,
|
||||
ParentId: ParentId,
|
||||
Ancestors: updatedAncestors,
|
||||
IsActive: true
|
||||
});
|
||||
}
|
||||
const isTeam = await team.first();
|
||||
if (isTeam) {
|
||||
props.setIsAlert({ type: "info", msg: "Teams already exists." });
|
||||
setIsLoader(false);
|
||||
} else {
|
||||
const newTeam = new Parse.Object("contracts_Teams");
|
||||
newTeam.set("Name", formdata.name);
|
||||
if (updatedAncestors.length > 0) {
|
||||
const ParentId = updatedAncestors[updatedAncestors.length - 1];
|
||||
newTeam.set("ParentId", ParentId);
|
||||
newTeam.set("Ancestors", updatedAncestors);
|
||||
}
|
||||
if (localUser && localUser.OrganizationId) {
|
||||
newTeam.set("OrganizationId", {
|
||||
__type: "Pointer",
|
||||
className: "contracts_Organizations",
|
||||
objectId: localUser.OrganizationId.objectId
|
||||
});
|
||||
}
|
||||
newTeam.set("IsActive", true);
|
||||
const newTeamRes = await newTeam.save();
|
||||
if (updatedAncestors.length > 0) {
|
||||
const ParentId = teamList.find((x) => x.objectId === formdata.team);
|
||||
props.handleTeamInfo({
|
||||
objectId: newTeamRes.id,
|
||||
Name: formdata.name,
|
||||
ParentId: ParentId,
|
||||
Ancestors: updatedAncestors,
|
||||
IsActive: true
|
||||
});
|
||||
} else {
|
||||
props.handleTeamInfo({
|
||||
objectId: newTeamRes.id,
|
||||
Name: formdata.name,
|
||||
ParentId: "",
|
||||
Ancestors: "",
|
||||
IsActive: true
|
||||
});
|
||||
}
|
||||
|
||||
if (props.closePopup) {
|
||||
props.closePopup();
|
||||
}
|
||||
setFormdata({
|
||||
name: "",
|
||||
team: { name: "", objectId: "" }
|
||||
});
|
||||
props.setIsAlert({
|
||||
type: "success",
|
||||
msg: "Team created successfully."
|
||||
props.handleTeamInfo({
|
||||
objectId: newTeamRes.id,
|
||||
Name: formdata.name,
|
||||
ParentId: "",
|
||||
Ancestors: "",
|
||||
IsActive: true
|
||||
});
|
||||
}
|
||||
if (props.closePopup) {
|
||||
props.closePopup();
|
||||
}
|
||||
setFormdata({ name: "", team: { name: "", objectId: "" } });
|
||||
props.setIsAlert({ type: "success", msg: "Team created successfully." });
|
||||
} catch (err) {
|
||||
console.log("err in save team", err);
|
||||
props.setIsAlert({ type: "danger", msg: "Something went wrong." });
|
||||
if (err.code === 137) {
|
||||
props.setIsAlert({ type: "danger", msg: "Teams already exists." });
|
||||
} else if (err.code === 102) {
|
||||
props.setIsAlert({ type: "warning", msg: "Provide team name." });
|
||||
} else {
|
||||
props.setIsAlert({ type: "danger", msg: "Something went wrong." });
|
||||
}
|
||||
} finally {
|
||||
setTimeout(() => props.setIsAlert({ type: "success", msg: "" }), 1500);
|
||||
setIsLoader(false);
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useState } from "react";
|
||||
import { saveAs } from "file-saver";
|
||||
import axios from "axios";
|
||||
import { getBase64FromUrl } from "../../constant/Utils";
|
||||
import { themeColor } from "../../constant/const";
|
||||
import { themeColor, emailRegex } from "../../constant/const";
|
||||
import printModule from "print-js";
|
||||
import Loader from "../../primitives/Loader";
|
||||
import ModalUi from "../../primitives/ModalUi";
|
||||
@@ -19,8 +19,9 @@ function EmailComponent({
|
||||
activeMailAdapter
|
||||
}) {
|
||||
const [emailList, setEmailList] = useState([]);
|
||||
const [emailValue, setEmailValue] = useState();
|
||||
const [emailValue, setEmailValue] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [emailErr, setEmailErr] = useState(false);
|
||||
//function for send email
|
||||
const sendEmail = async () => {
|
||||
setIsLoading(true);
|
||||
@@ -111,17 +112,30 @@ function EmailComponent({
|
||||
//function for get email value
|
||||
const handleEmailValue = (e) => {
|
||||
const value = e.target.value;
|
||||
setEmailErr(false);
|
||||
setEmailValue(value);
|
||||
};
|
||||
|
||||
//function for save email in array after press enter
|
||||
const handleEnterPress = (e) => {
|
||||
const pattern = emailRegex;
|
||||
const validate = emailValue?.match(pattern);
|
||||
if (e.key === "Enter" && emailValue) {
|
||||
setEmailList((prev) => [...prev, emailValue]);
|
||||
setEmailValue("");
|
||||
if (validate) {
|
||||
const emailLowerCase = emailValue?.toLowerCase();
|
||||
setEmailList((prev) => [...prev, emailLowerCase]);
|
||||
setEmailValue("");
|
||||
} else {
|
||||
setEmailErr(true);
|
||||
}
|
||||
} else if (e === "add" && emailValue) {
|
||||
setEmailList((prev) => [...prev, emailValue]);
|
||||
setEmailValue("");
|
||||
if (validate) {
|
||||
const emailLowerCase = emailValue?.toLowerCase();
|
||||
setEmailList((prev) => [...prev, emailLowerCase]);
|
||||
setEmailValue("");
|
||||
} else {
|
||||
setEmailErr(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -179,7 +193,6 @@ function EmailComponent({
|
||||
Successfully signed!
|
||||
</span>
|
||||
<div className="flex flex-row">
|
||||
<div></div>
|
||||
{!isAndroid && (
|
||||
<button
|
||||
onClick={handleToPrint}
|
||||
@@ -203,72 +216,63 @@ function EmailComponent({
|
||||
Recipients added here will get a copy of the signed document.
|
||||
</p>
|
||||
{emailList.length > 0 ? (
|
||||
<>
|
||||
<div className="p-0 border-[1.5px] op-border-primary rounded w-full text-[15px]">
|
||||
<div className="flex flex-row flex-wrap">
|
||||
{emailList.map((data, ind) => {
|
||||
return (
|
||||
<div
|
||||
className="flex flex-row items-center op-bg-primary m-[4px] rounded-md py-[5px] px-[10px]"
|
||||
key={ind}
|
||||
<div className="p-0 border-[1.5px] op-border-primary rounded w-full text-[15px]">
|
||||
<div className="flex flex-row flex-wrap">
|
||||
{emailList.map((data, ind) => {
|
||||
return (
|
||||
<div
|
||||
className="flex flex-row items-center op-bg-primary m-[4px] rounded-md py-[5px] px-[10px]"
|
||||
key={ind}
|
||||
>
|
||||
<span className="text-base-100 text-[13px]">
|
||||
{data}
|
||||
</span>
|
||||
<span
|
||||
className="text-base-100 text-[13px] font-semibold ml-[7px] cursor-pointer"
|
||||
onClick={() => removeChip(ind)}
|
||||
>
|
||||
<span className="text-base-100 text-[13px]">
|
||||
{data}
|
||||
</span>
|
||||
<span
|
||||
className="text-base-100 text-[13px] font-semibold ml-[7px] cursor-pointer"
|
||||
onClick={() => removeChip(ind)}
|
||||
>
|
||||
<i className="fa-light fa-xmark"></i>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{emailList.length <= 9 && (
|
||||
<input
|
||||
type="text"
|
||||
value={emailValue}
|
||||
className="p-[10px] pb-[20px] rounded w-full text-[15px] bg-transparent outline-none"
|
||||
onChange={handleEmailValue}
|
||||
onKeyDown={handleEnterPress}
|
||||
onBlur={() => {
|
||||
if (emailValue) {
|
||||
handleEnterPress("add");
|
||||
}
|
||||
}}
|
||||
required
|
||||
/>
|
||||
)}
|
||||
<i className="fa-light fa-xmark"></i>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
{emailList.length <= 9 && (
|
||||
<input
|
||||
type="email"
|
||||
value={emailValue}
|
||||
className="p-[10px] pb-[20px] rounded w-full text-[15px] bg-transparent outline-none"
|
||||
onChange={handleEmailValue}
|
||||
onKeyDown={handleEnterPress}
|
||||
onBlur={() => emailValue && handleEnterPress("add")}
|
||||
required
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
type="email"
|
||||
value={emailValue}
|
||||
className="p-[10px] pb-[20px] rounded w-full text-[15px] outline-none bg-transparent border-[1.5px] op-border-primary"
|
||||
onChange={handleEmailValue}
|
||||
onKeyDown={handleEnterPress}
|
||||
placeholder="Add the email addresses"
|
||||
onBlur={() => {
|
||||
if (emailValue) {
|
||||
handleEnterPress("add");
|
||||
}
|
||||
}}
|
||||
placeholder="Add an email address and hit enter"
|
||||
onBlur={() => emailValue && handleEnterPress("add")}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{emailErr && (
|
||||
<p className="text-xs text-[red] ml-1.5 mt-0.5">
|
||||
please provide correct email address
|
||||
</p>
|
||||
)}
|
||||
<button
|
||||
className={`${
|
||||
emailValue ? "cursor-pointer" : "cursor-default"
|
||||
} op-btn op-btn-primary op-btn-sm m-2 shadow-md`}
|
||||
onClick={() => {
|
||||
if (emailValue) {
|
||||
handleEnterPress("add");
|
||||
}
|
||||
}}
|
||||
onClick={() => emailValue && handleEnterPress("add")}
|
||||
>
|
||||
<i className="fa-light fa-plus" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
@@ -13,6 +13,7 @@ import DatePicker from "react-datepicker";
|
||||
import "react-datepicker/dist/react-datepicker.css";
|
||||
import "../../styles/signature.css";
|
||||
import RegexParser from "regex-parser";
|
||||
import { emailRegex } from "../../constant/const";
|
||||
const textWidgetCls =
|
||||
"w-full h-full md:min-w-full md:min-h-full z-[999] text-[12px] rounded-[2px] border-[1px] border-[#007bff] overflow-hidden resize-none outline-none text-base-content item-center whitespace-pre-wrap";
|
||||
const selectWidgetCls =
|
||||
@@ -61,7 +62,7 @@ function PlaceholderType(props) {
|
||||
if (validateType && validateType !== "text") {
|
||||
switch (validateType) {
|
||||
case "email":
|
||||
regexValidation = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
||||
regexValidation = emailRegex;
|
||||
validateExpression(regexValidation);
|
||||
break;
|
||||
case "number":
|
||||
|
||||
@@ -149,7 +149,6 @@ function SignPad({
|
||||
const isWidgetType = currWidgetsDetails?.type;
|
||||
const signatureType = currWidgetsDetails?.signatureType;
|
||||
const url = currWidgetsDetails?.SignUrl;
|
||||
|
||||
//checking widget type and draw type signature url
|
||||
if (isInitial) {
|
||||
if (isWidgetType === "initials" && signatureType === "draw" && url) {
|
||||
@@ -299,8 +298,9 @@ function SignPad({
|
||||
<div className="flex flex-row justify-between mt-[3px]">
|
||||
<div className="flex flex-row justify-between gap-[5px] md:gap-[8px] text-[11px] md:text-base">
|
||||
{isStamp ? (
|
||||
<span className="op-link-primary op-link">
|
||||
{widgetType === "image"
|
||||
<span className="text-base-content font-bold text-lg">
|
||||
{widgetType === "image" ||
|
||||
currWidgetsDetails?.type === "image"
|
||||
? "Upload image"
|
||||
: "Upload stamp image"}
|
||||
</span>
|
||||
|
||||
@@ -3,10 +3,11 @@ export const templateCls = "contracts_Template";
|
||||
export const documentCls = "contracts_Document";
|
||||
export const themeColor = "#47a3ad";
|
||||
export const iconColor = "#686968";
|
||||
export const isEnableSubscription =
|
||||
process.env.REACT_APP_ENABLE_SUBSCRIPTION &&
|
||||
process.env.REACT_APP_ENABLE_SUBSCRIPTION?.toLowerCase() === "true"
|
||||
? true
|
||||
: false;
|
||||
export const isStaging =
|
||||
window.location.origin === "https://staging-app.opensignlabs.com";
|
||||
export const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
||||
export const isEnableSubscription = true;
|
||||
// process.env.REACT_APP_ENABLE_SUBSCRIPTION &&
|
||||
// process.env.REACT_APP_ENABLE_SUBSCRIPTION?.toLowerCase() === "true"
|
||||
// ? true
|
||||
// : false;
|
||||
export const isStaging = "http://localhost:3001";
|
||||
// window.location.origin === "https://staging-app.opensignlabs.com";
|
||||
|
||||
@@ -113,16 +113,9 @@ const TeamList = () => {
|
||||
: false;
|
||||
setIsAdmin(admin);
|
||||
}
|
||||
const teamCls = new Parse.Query("contracts_Teams");
|
||||
teamCls.equalTo("OrganizationId", {
|
||||
__type: "Pointer",
|
||||
className: "contracts_Organizations",
|
||||
objectId: extUser.OrganizationId.objectId
|
||||
});
|
||||
teamCls.descending("createdAt");
|
||||
const teamRes = await teamCls.find();
|
||||
if (teamRes.length > 0) {
|
||||
const _teamRes = JSON.parse(JSON.stringify(teamRes));
|
||||
const teams = await Parse.Cloud.run("getteams");
|
||||
if (teams.length > 0) {
|
||||
const _teamRes = JSON.parse(JSON.stringify(teams));
|
||||
setTeamList(_teamRes);
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -169,10 +162,11 @@ const TeamList = () => {
|
||||
newArray[index] = { ...newArray[index], IsActive: !IsActive };
|
||||
setTeamList(newArray);
|
||||
try {
|
||||
const teamCls = new Parse.Object("contracts_Teams");
|
||||
teamCls.id = team.objectId;
|
||||
teamCls.set("IsActive", !IsActive);
|
||||
await teamCls.save();
|
||||
await Parse.Cloud.run("updateteam", {
|
||||
IsActive: !IsActive,
|
||||
TeamId: team.objectId
|
||||
});
|
||||
// console.log("teamRes ", teamRes);
|
||||
setIsAlert({
|
||||
type: !IsActive === false ? "danger" : "success",
|
||||
msg: !IsActive === false ? "Team disabled." : "Team enabled."
|
||||
@@ -203,10 +197,9 @@ const TeamList = () => {
|
||||
setIsActLoader({ [team.objectId]: true });
|
||||
setIsEditModal({});
|
||||
try {
|
||||
const teamCls = new Parse.Object("contracts_Teams");
|
||||
teamCls.id = team?.objectId;
|
||||
teamCls.set("Name", team.Name);
|
||||
await teamCls.save();
|
||||
const data = { Name: team.Name, TeamId: team.objectId };
|
||||
await Parse.Cloud.run("updateteam", data);
|
||||
// console.log("updateTeamRes ", updateTeamRes);
|
||||
setIsAlert({ type: "success", msg: "Team Update successfully." });
|
||||
} catch (Err) {
|
||||
console.log("Err in update team name"), Err;
|
||||
|
||||
@@ -145,14 +145,7 @@ const ReportTable = (props) => {
|
||||
try {
|
||||
const extUser = JSON.parse(localStorage.getItem("Extand_Class"))?.[0];
|
||||
if (extUser?.OrganizationId?.objectId) {
|
||||
const team = new Parse.Query("contracts_Teams");
|
||||
team.equalTo("OrganizationId", {
|
||||
__type: "Pointer",
|
||||
className: "contracts_Organizations",
|
||||
objectId: extUser.OrganizationId.objectId
|
||||
});
|
||||
team.notEqualTo("IsActive", false);
|
||||
const teamtRes = await team.find();
|
||||
const teamtRes = await Parse.Cloud.run("getteams");
|
||||
if (teamtRes.length > 0) {
|
||||
const _teamRes = JSON.parse(JSON.stringify(teamtRes));
|
||||
const formatedList = _teamRes.map((x) => ({
|
||||
|
||||
@@ -52,6 +52,12 @@ import AddAdmin from './parsefunction/AddAdmin.js';
|
||||
import CheckAdminExist from './parsefunction/CheckAdminExist.js';
|
||||
import UpdateExistUserAsAdmin from './parsefunction/UpdateExistUserAsAdmin.js';
|
||||
import Newsletter from './parsefunction/Newsletter.js';
|
||||
import getOrganizations from './parsefunction/getOrganizations.js';
|
||||
import addOrganization from './parsefunction/addOrganization.js';
|
||||
import updateOrganization from './parsefunction/updateOrganization.js';
|
||||
import getTeams from './parsefunction/getTeams.js';
|
||||
import addTeam from './parsefunction/addTeam.js';
|
||||
import updateTeam from './parsefunction/updateTeam.js';
|
||||
|
||||
// This afterSave function triggers after an object is added or updated in the specified class, allowing for post-processing logic.
|
||||
Parse.Cloud.afterSave('contracts_Document', DocumentAftersave);
|
||||
@@ -113,3 +119,9 @@ Parse.Cloud.define('addadmin', AddAdmin);
|
||||
Parse.Cloud.define('checkadminexist', CheckAdminExist);
|
||||
Parse.Cloud.define('updateuserasadmin', UpdateExistUserAsAdmin);
|
||||
Parse.Cloud.define('newsletter', Newsletter);
|
||||
Parse.Cloud.define('getorganizations', getOrganizations);
|
||||
Parse.Cloud.define('addorganization', addOrganization);
|
||||
Parse.Cloud.define('updateorganization', updateOrganization);
|
||||
Parse.Cloud.define('getteams', getTeams);
|
||||
Parse.Cloud.define('addteam', addTeam);
|
||||
Parse.Cloud.define('updateteam', updateTeam);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
export default async function addOrganization(request) {
|
||||
const name = request.params.name;
|
||||
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
try {
|
||||
const extUserQuery = new Parse.Query('contracts_Users');
|
||||
extUserQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
extUserQuery.notEqualTo('IsDisabled', true);
|
||||
const resExt = await extUserQuery.first({ useMasterKey: true });
|
||||
if (!resExt) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'User not found.');
|
||||
}
|
||||
const _resExt = JSON.parse(JSON.stringify(resExt));
|
||||
|
||||
const orgQuery = new Parse.Query('contracts_Organizations');
|
||||
orgQuery.equalTo('Name', name);
|
||||
orgQuery.equalTo('CreatedBy', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
const resOrg = await orgQuery.first({ useMasterKey: true });
|
||||
if (resOrg) {
|
||||
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, 'Organization already exists.');
|
||||
} else {
|
||||
const newOrg = new Parse.Object('contracts_Organizations');
|
||||
newOrg.set('Name', name);
|
||||
newOrg.set('IsActive', true);
|
||||
newOrg.set('CreatedBy', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
newOrg.set('TenantId', {
|
||||
__type: 'Pointer',
|
||||
className: 'partners_Tenant',
|
||||
objectId: _resExt.TenantId.objectId,
|
||||
});
|
||||
newOrg.set('ExtUserId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Users',
|
||||
objectId: resExt.id,
|
||||
});
|
||||
const newResOrg = await newOrg.save(null, { useMasterKey: true });
|
||||
if (newResOrg) {
|
||||
return newResOrg;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in addorganization', err);
|
||||
const code = err?.code || 400;
|
||||
const msg = err?.message || 'Something went wrong.';
|
||||
throw new Parse.Error(code, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
export default async function addTeam(request) {
|
||||
const Name = request.params.Name;
|
||||
const ParentId = request.params.ParentId;
|
||||
const Ancestors = request.params.Ancestors;
|
||||
const ParentPtr = { __type: 'Pointer', className: 'contracts_Teams', objectId: ParentId };
|
||||
if (Name) {
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
try {
|
||||
const extUserQuery = new Parse.Query('contracts_Users');
|
||||
extUserQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
extUserQuery.notEqualTo('IsDisabled', true);
|
||||
const resExt = await extUserQuery.first({ useMasterKey: true });
|
||||
const extUser = JSON.parse(JSON.stringify(resExt));
|
||||
if (!extUser) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'User not found.');
|
||||
}
|
||||
const teamCls = new Parse.Query('contracts_Teams');
|
||||
teamCls.equalTo('Name', Name);
|
||||
teamCls.equalTo('OrganizationId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Organizations',
|
||||
objectId: extUser.OrganizationId.objectId,
|
||||
});
|
||||
if (ParentId) {
|
||||
teamCls.equalTo('ParentId', ParentPtr);
|
||||
}
|
||||
const teamRes = await teamCls.first({ useMasterKey: true });
|
||||
if (teamRes) {
|
||||
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, 'Team already exists.');
|
||||
} else {
|
||||
const newteam = new Parse.Object('contracts_Teams');
|
||||
newteam.set('Name', Name);
|
||||
newteam.set('OrganizationId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Organizations',
|
||||
objectId: extUser.OrganizationId.objectId,
|
||||
});
|
||||
if (ParentId) {
|
||||
newteam.set('ParentId', ParentPtr);
|
||||
}
|
||||
if (Ancestors && Ancestors.length > 0) {
|
||||
newteam.set('Ancestors', Ancestors);
|
||||
}
|
||||
newteam.set('IsActive', true);
|
||||
const newTeamRes = await newteam.save(null, { useMasterKey: true });
|
||||
return newTeamRes;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in getOrganizations', err);
|
||||
const code = err?.code || 400;
|
||||
const msg = err?.message || 'Something went wrong.';
|
||||
throw new Parse.Error(code, msg);
|
||||
}
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Please provide parameters');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
export default async function getOrganizations(request) {
|
||||
const limit = request.params.limit || 200;
|
||||
const skip = request.params.skip || 0;
|
||||
const extUserId = request.params.extUserId;
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
try {
|
||||
const orgQuery = new Parse.Query('contracts_Organizations');
|
||||
orgQuery.equalTo('CreatedBy', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
orgQuery.equalTo('ExtUserId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Users',
|
||||
objectId: extUserId,
|
||||
});
|
||||
orgQuery.equalTo('IsActive', true);
|
||||
orgQuery.exclude('ExtUserId');
|
||||
orgQuery.limit(limit);
|
||||
orgQuery.skip(skip);
|
||||
const resOrg = await orgQuery.find({ useMasterKey: true });
|
||||
if (resOrg && resOrg.length > 0) {
|
||||
return resOrg;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in getOrganizations', err);
|
||||
const code = err?.code || 400;
|
||||
const msg = err?.message || 'Something went wrong.';
|
||||
throw new Parse.Error(code, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
export default async function getTeams(request) {
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
try {
|
||||
const extUserQuery = new Parse.Query('contracts_Users');
|
||||
extUserQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
extUserQuery.notEqualTo('IsDisabled', true);
|
||||
const resExt = await extUserQuery.first({ useMasterKey: true });
|
||||
const extUser = JSON.parse(JSON.stringify(resExt));
|
||||
const teamCls = new Parse.Query('contracts_Teams');
|
||||
teamCls.equalTo('OrganizationId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Organizations',
|
||||
objectId: extUser.OrganizationId.objectId,
|
||||
});
|
||||
teamCls.equalTo('IsActive', true);
|
||||
teamCls.descending('createdAt');
|
||||
const teamRes = await teamCls.find({ useMasterKey: true });
|
||||
if (teamRes && teamRes.length > 0) {
|
||||
return teamRes;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in getOrganizations', err);
|
||||
const code = err?.code || 400;
|
||||
const msg = err?.message || 'Something went wrong.';
|
||||
throw new Parse.Error(code, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
export default async function updateOrganization(request) {
|
||||
const orgId = request.params.orgId;
|
||||
const isactive = request.params.isactive;
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
try {
|
||||
const orgQuery = new Parse.Query('contracts_Organizations');
|
||||
orgQuery.equalTo('objectId', orgId);
|
||||
orgQuery.equalTo('CreatedBy', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
const resOrg = await orgQuery.first({ useMasterKey: true });
|
||||
if (resOrg) {
|
||||
const newOrg = new Parse.Object('contracts_Organizations');
|
||||
newOrg.id = orgId;
|
||||
newOrg.set('IsActive', isactive);
|
||||
const newResOrg = await newOrg.save(null, { useMasterKey: true });
|
||||
if (newResOrg) {
|
||||
return newResOrg;
|
||||
}
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'Premission denied.');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in addorganization', err);
|
||||
const code = err?.code || 400;
|
||||
const msg = err?.message || 'Something went wrong.';
|
||||
throw new Parse.Error(code, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
export default async function updateTeam(request) {
|
||||
const TeamId = request.params.TeamId;
|
||||
const IsActive = request.params.IsActive;
|
||||
const Name = request.params.Name;
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
try {
|
||||
const extUserQuery = new Parse.Query('contracts_Users');
|
||||
extUserQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
extUserQuery.notEqualTo('IsDisabled', true);
|
||||
const resExt = await extUserQuery.first({ useMasterKey: true });
|
||||
const extUser = JSON.parse(JSON.stringify(resExt));
|
||||
if (!extUser) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'User not found.');
|
||||
}
|
||||
const teamCls = new Parse.Query('contracts_Teams');
|
||||
teamCls.equalTo('objectId', TeamId);
|
||||
teamCls.equalTo('OrganizationId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Organizations',
|
||||
objectId: extUser.OrganizationId.objectId,
|
||||
});
|
||||
const teamRes = await teamCls.first({ useMasterKey: true });
|
||||
if (teamRes) {
|
||||
const updateteam = new Parse.Object('contracts_Teams');
|
||||
updateteam.id = TeamId;
|
||||
if (Name) {
|
||||
updateteam.set('Name', Name);
|
||||
}
|
||||
if (IsActive) {
|
||||
updateteam.set('IsActive', IsActive);
|
||||
}
|
||||
const updateTeamRes = await updateteam.save(null, { useMasterKey: true });
|
||||
return updateTeamRes;
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'Premission denied.');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in getOrganizations', err);
|
||||
const code = err?.code || 400;
|
||||
const msg = err?.message || 'Something went wrong.';
|
||||
throw new Parse.Error(code, msg);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,16 @@ exports.up = async Parse => {
|
||||
.addBoolean('HeaderDocId')
|
||||
.addPointer('CreatedBy', '_User')
|
||||
.addString('Webhook')
|
||||
.addBoolean('ShareWithTeam', false);
|
||||
.addBoolean('ShareWithTeam', false)
|
||||
.setCLP({
|
||||
get: {},
|
||||
find: {},
|
||||
count: {},
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: {},
|
||||
addField: {},
|
||||
});
|
||||
await extUsers.save(null, { useMasterKey: true });
|
||||
|
||||
const doc = new Parse.Schema('contracts_Document');
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
*
|
||||
* @param {Parse} Parse
|
||||
*/
|
||||
exports.up = async Parse => {
|
||||
const teamSchema = new Parse.Schema('contracts_Teams');
|
||||
teamSchema.setCLP({
|
||||
get: {},
|
||||
find: {},
|
||||
count: {},
|
||||
create: {},
|
||||
update: {},
|
||||
delete: {},
|
||||
addField: {},
|
||||
});
|
||||
await teamSchema.update();
|
||||
|
||||
const orgSchema = new Parse.Schema('contracts_Organizations');
|
||||
orgSchema.setCLP({
|
||||
get: {},
|
||||
find: {},
|
||||
count: {},
|
||||
create: {},
|
||||
update: {},
|
||||
delete: {},
|
||||
addField: {},
|
||||
});
|
||||
|
||||
return orgSchema.update();
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Parse} Parse
|
||||
*/
|
||||
exports.down = async Parse => {
|
||||
const teamSchema = new Parse.Schema('contracts_Teams');
|
||||
teamSchema.setCLP({
|
||||
get: { '*': true },
|
||||
find: { '*': true },
|
||||
count: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
});
|
||||
await teamSchema.update();
|
||||
|
||||
const orgSchema = new Parse.Schema('contracts_Organizations');
|
||||
orgSchema.setCLP({
|
||||
get: { '*': true },
|
||||
find: { '*': true },
|
||||
count: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
});
|
||||
|
||||
return orgSchema.update();
|
||||
};
|
||||
Reference in New Issue
Block a user