Continued with the entities for the batch users
This commit is contained in:
@@ -5,6 +5,8 @@ import { FirebaseScrypt } from 'firebase-scrypt';
|
||||
import { firebaseAuthScryptParams } from "@/firebase";
|
||||
import crypto from 'crypto';
|
||||
import axios from "axios";
|
||||
import { getEntityWithRoles } from "@/utils/entities.be";
|
||||
import { findBy } from "@/utils";
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -47,7 +49,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const salt = crypto.randomBytes(16).toString('base64');
|
||||
const hash = await scrypt.hash(user.passport_id, salt);
|
||||
|
||||
currentUser.entities = [{ id: currentUser.entity!, role: "90ce8f08-08c8-41e4-9848-f1500ddc3930" }]
|
||||
const entity = await getEntityWithRoles(currentUser.entity!)
|
||||
const defaultRole = findBy(entity?.roles || [], "isDefault", true)
|
||||
|
||||
currentUser.entities = [{ id: entity?.id || "", role: defaultRole?.id || "" }]
|
||||
delete currentUser.entity
|
||||
|
||||
currentUser.email = currentUser.email.toLowerCase();
|
||||
|
||||
@@ -10,6 +10,8 @@ import { getGroup, getGroups, getUserCorporate, getUserGroups, getUserNamedGroup
|
||||
import { uniq } from "lodash";
|
||||
import { getSpecificUsers, getUser } from "@/utils/users.be";
|
||||
import client from "@/lib/mongodb";
|
||||
import { getEntityWithRoles } from "@/utils/entities.be";
|
||||
import { findBy } from "@/utils";
|
||||
|
||||
const DEFAULT_DESIRED_LEVELS = {
|
||||
reading: 9,
|
||||
@@ -65,6 +67,9 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
.then(async (userCredentials) => {
|
||||
const userId = userCredentials.user.uid;
|
||||
|
||||
const entityWithRole = await getEntityWithRoles(entity)
|
||||
const defaultRole = findBy(entityWithRole?.roles || [], "isDefault", true)
|
||||
|
||||
const user = {
|
||||
...req.body,
|
||||
bio: "",
|
||||
@@ -78,7 +83,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
isFirstLogin: false,
|
||||
isVerified: true,
|
||||
registrationDate: new Date(),
|
||||
entities: [{ id: entity, role: "90ce8f08-08c8-41e4-9848-f1500ddc3930" }],
|
||||
entities: [{ id: entity, role: defaultRole?.id || "" }],
|
||||
subscriptionExpirationDate: expiryDate || null,
|
||||
...((maker.type === "corporate" || maker.type === "mastercorporate") && type === "corporate"
|
||||
? {
|
||||
|
||||
Reference in New Issue
Block a user