feat: Implement user ID duplication check in user registration and update processes
- Added functionality to check for existing user IDs during new user registration and updates to prevent overwriting accounts from different companies. - Enhanced error handling to return appropriate messages when a duplicate user ID is detected. - Updated the frontend to include user ID duplication verification, ensuring a smoother user experience during user creation and editing. - These changes aim to improve data integrity and user management across multiple company implementations.
This commit is contained in:
@@ -45,7 +45,7 @@ export async function createPkgUnit(
|
||||
const {
|
||||
pkg_code, pkg_name, pkg_type, status,
|
||||
width_mm, length_mm, height_mm,
|
||||
self_weight_kg, max_load_kg, volume_l, remarks,
|
||||
self_weight_kg, max_load_kg, volume_l, remarks, item_number,
|
||||
} = req.body;
|
||||
|
||||
if (!pkg_code || !pkg_name) {
|
||||
@@ -64,12 +64,12 @@ export async function createPkgUnit(
|
||||
|
||||
const result = await pool.query(
|
||||
`INSERT INTO pkg_unit
|
||||
(company_code, pkg_code, pkg_name, pkg_type, status,
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, volume_l, remarks, writer)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
|
||||
(id, company_code, pkg_code, pkg_name, pkg_type, status,
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, volume_l, remarks, item_number, writer, created_date)
|
||||
VALUES (gen_random_uuid()::text, $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14, NOW())
|
||||
RETURNING *`,
|
||||
[companyCode, pkg_code, pkg_name, pkg_type, status || "ACTIVE",
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, volume_l, remarks,
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, volume_l, remarks, item_number || pkg_code,
|
||||
req.user!.userId]
|
||||
);
|
||||
|
||||
@@ -92,7 +92,7 @@ export async function updatePkgUnit(
|
||||
const {
|
||||
pkg_name, pkg_type, status,
|
||||
width_mm, length_mm, height_mm,
|
||||
self_weight_kg, max_load_kg, volume_l, remarks,
|
||||
self_weight_kg, max_load_kg, volume_l, remarks, item_number,
|
||||
} = req.body;
|
||||
|
||||
const result = await pool.query(
|
||||
@@ -100,12 +100,14 @@ export async function updatePkgUnit(
|
||||
pkg_name=$1, pkg_type=$2, status=$3,
|
||||
width_mm=$4, length_mm=$5, height_mm=$6,
|
||||
self_weight_kg=$7, max_load_kg=$8, volume_l=$9, remarks=$10,
|
||||
updated_date=NOW(), writer=$11
|
||||
WHERE id=$12 AND company_code=$13
|
||||
item_number=COALESCE($11, item_number),
|
||||
updated_date=NOW(), writer=$12
|
||||
WHERE id=$13 AND company_code=$14
|
||||
RETURNING *`,
|
||||
[pkg_name, pkg_type, status,
|
||||
width_mm, length_mm, height_mm,
|
||||
self_weight_kg, max_load_kg, volume_l, remarks,
|
||||
item_number,
|
||||
req.user!.userId, id, companyCode]
|
||||
);
|
||||
|
||||
@@ -286,7 +288,7 @@ export async function createLoadingUnit(
|
||||
const {
|
||||
loading_code, loading_name, loading_type, status,
|
||||
width_mm, length_mm, height_mm,
|
||||
self_weight_kg, max_load_kg, max_stack, remarks,
|
||||
self_weight_kg, max_load_kg, max_stack, remarks, item_number,
|
||||
} = req.body;
|
||||
|
||||
if (!loading_code || !loading_name) {
|
||||
@@ -305,12 +307,12 @@ export async function createLoadingUnit(
|
||||
|
||||
const result = await pool.query(
|
||||
`INSERT INTO loading_unit
|
||||
(company_code, loading_code, loading_name, loading_type, status,
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, max_stack, remarks, writer)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
|
||||
(id, company_code, loading_code, loading_name, loading_type, status,
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, max_stack, remarks, item_number, writer, created_date)
|
||||
VALUES (gen_random_uuid()::text, $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14, NOW())
|
||||
RETURNING *`,
|
||||
[companyCode, loading_code, loading_name, loading_type, status || "ACTIVE",
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, max_stack, remarks,
|
||||
width_mm, length_mm, height_mm, self_weight_kg, max_load_kg, max_stack, remarks, item_number || loading_code,
|
||||
req.user!.userId]
|
||||
);
|
||||
|
||||
@@ -333,7 +335,7 @@ export async function updateLoadingUnit(
|
||||
const {
|
||||
loading_name, loading_type, status,
|
||||
width_mm, length_mm, height_mm,
|
||||
self_weight_kg, max_load_kg, max_stack, remarks,
|
||||
self_weight_kg, max_load_kg, max_stack, remarks, item_number,
|
||||
} = req.body;
|
||||
|
||||
const result = await pool.query(
|
||||
@@ -341,12 +343,14 @@ export async function updateLoadingUnit(
|
||||
loading_name=$1, loading_type=$2, status=$3,
|
||||
width_mm=$4, length_mm=$5, height_mm=$6,
|
||||
self_weight_kg=$7, max_load_kg=$8, max_stack=$9, remarks=$10,
|
||||
updated_date=NOW(), writer=$11
|
||||
WHERE id=$12 AND company_code=$13
|
||||
item_number=COALESCE($11, item_number),
|
||||
updated_date=NOW(), writer=$12
|
||||
WHERE id=$13 AND company_code=$14
|
||||
RETURNING *`,
|
||||
[loading_name, loading_type, status,
|
||||
width_mm, length_mm, height_mm,
|
||||
self_weight_kg, max_load_kg, max_stack, remarks,
|
||||
item_number,
|
||||
req.user!.userId, id, companyCode]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user