fix: migration function

This commit is contained in:
prafull-opensignlabs
2024-07-17 15:13:14 +05:30
parent f7087dfb29
commit 1eafc113e6
6 changed files with 31 additions and 48 deletions
File diff suppressed because one or more lines are too long
+3
View File
@@ -106,6 +106,9 @@ const AddUser = (props) => {
objectId: localUser.OrganizationId.objectId
});
}
if (localUser && localUser.Company) {
extUser.set("Company", localUser.Company);
}
if (localStorage.getItem("TenantId")) {
extUser.set("TenantId", {
@@ -1,11 +0,0 @@
import React from "react";
const PremiumAlertHeader = ({ message }) => (
<marquee className="bg-yellow-300 text-black px-2">
{message
? message
: "Currently free in Beta, this feature will incur a fee later."}
</marquee>
);
export default PremiumAlertHeader;
@@ -3,10 +3,10 @@ export default async function CheckAdminExist() {
try {
const extClsQuery = new Parse.Query('contracts_Users');
extClsQuery.equalTo('UserRole', 'contracts_Admin');
extClsQuery.exists('OrganizationId');
extClsQuery.notEqualTo('IsDisabled', true);
const extAdminRes = await extClsQuery.first({ useMasterKey: true });
if (extAdminRes) {
const extAdminRes = await extClsQuery.find({ useMasterKey: true });
// must be only one admin
if (extAdminRes && extAdminRes.length === 1 && extAdminRes?.[0]?.get('OrganizationId')) {
return 'exist';
} else {
return 'not_exist';
@@ -6,7 +6,7 @@ async function updateUserExceptAdmin(data) {
while (hasMore) {
const query = new Parse.Query(Contracts);
query.notEqualTo('UserRole', 'contracts_Admin');
query.notEqualTo('Email', data.email);
query.limit(limit);
query.skip(skip);
@@ -24,6 +24,8 @@ async function updateUserExceptAdmin(data) {
contract.set('UserRole', 'contracts_User');
contract.set('OrganizationId', data.orgPtr);
contract.set('TeamIds', data.teamIds);
contract.set('CreatedBy', data.createdBy);
contract.set('TenantId', data.tenantId);
}
// Save all the updated entries
@@ -46,11 +48,9 @@ export default async function UpdateExistUserAsAdmin(request) {
}
const extClsQuery = new Parse.Query('contracts_Users');
extClsQuery.equalTo('UserRole', 'contracts_Admin');
extClsQuery.exists('OrganizationId');
extClsQuery.exists('TeamIds');
extClsQuery.notEqualTo('IsDisabled', true);
const extAdminRes = await extClsQuery.first({ useMasterKey: true });
if (extAdminRes) {
const extAdminRes = await extClsQuery.find({ useMasterKey: true });
if (extAdminRes && extAdminRes.length === 1 && extAdminRes?.[0]?.get('OrganizationId')) {
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, 'Admin already exist.');
} else {
const extCls = new Parse.Query('contracts_Users');
@@ -60,24 +60,26 @@ export default async function UpdateExistUserAsAdmin(request) {
console.log('extRes ', extRes);
if (extRes) {
const _extRes = JSON.parse(JSON.stringify(extRes));
const org = new Parse.Object('contracts_Organizations');
org.set('Name', _extRes.Company);
org.set('IsActive', true);
org.set('TenantId', {
const tenantId = {
__type: 'Pointer',
className: 'partners_Tenant',
objectId: _extRes.TenantId.objectId,
});
};
const createdBy = {
__type: 'Pointer',
className: '_User',
objectId: _extRes.UserId.objectId,
};
const org = new Parse.Object('contracts_Organizations');
org.set('Name', _extRes.Company);
org.set('IsActive', true);
org.set('TenantId', tenantId);
org.set('ExtUserId', {
__type: 'Pointer',
className: 'contracts_Users',
objectId: extRes.id,
});
org.set('CreatedBy', {
__type: 'Pointer',
className: '_User',
objectId: _extRes.UserId.objectId,
});
org.set('CreatedBy', createdBy);
const orgRes = await org.save(null, { useMasterKey: true });
const teamCls = new Parse.Object('contracts_Teams');
teamCls.set('Name', 'All Users');
@@ -107,7 +109,13 @@ export default async function UpdateExistUserAsAdmin(request) {
extUser.set('TeamIds', teamIds);
const extUserRes = await extUser.save(null, { useMasterKey: true });
if (extUserRes) {
const data = { orgPtr: orgPtr, teamIds: teamIds };
const data = {
orgPtr: orgPtr,
teamIds: teamIds,
email: email,
createdBy: createdBy,
tenantId: tenantId,
};
updateUserExceptAdmin(data);
return 'admin_created';
}
-17
View File
@@ -1,17 +0,0 @@
#!/bin/bash
echo "Starting MongoDB initial data import..."
# Wait for MongoDB to fully start
sleep 10
# Import the data
mongoimport --host localhost --db OpenSignDB --collection _Role --type json --file /docker-entrypoint-initdb.d/legadraGCva._Role.json --jsonArray
mongoimport --host localhost --db OpenSignDB --collection _SCHEMA --type json --file /docker-entrypoint-initdb.d/legadraGCva._SCHEMA.json --jsonArray
mongoimport --host localhost --db OpenSignDB --collection w_appinfo --type json --file /docker-entrypoint-initdb.d/legadraGCva.w_appinfo.json --jsonArray
mongoimport --host localhost --db OpenSignDB --collection w_dashboard --type json --file /docker-entrypoint-initdb.d/legadraGCva.w_dashboard.json --jsonArray
mongoimport --host localhost --db OpenSignDB --collection w_menu --type json --file /docker-entrypoint-initdb.d/legadraGCva.w_menu.json --jsonArray
echo "MongoDB initial data import done."