refactor: edit tailwindcss classes and change code formatting, therefore added .prettierrc file
fix: frontend bug where the passwords won't be checked when the password is changed
This commit is contained in:
@@ -1,48 +1,61 @@
|
||||
import mysql, {type ResultSetHeader, type RowDataPacket} from "mysql2/promise";
|
||||
import mysql, {
|
||||
type ResultSetHeader,
|
||||
type RowDataPacket,
|
||||
} from "mysql2/promise";
|
||||
import dotenv from "dotenv";
|
||||
import {returnErrorCode} from "../../../services/helperFuncs.js";
|
||||
import {PRODUCT_ERROR_CODE} from "@stockhome/shared";
|
||||
import { returnErrorCode } from "../../../services/helperFuncs.js";
|
||||
import { PRODUCT_ERROR_CODE } from "@stockhome/shared";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DB_HOST!,
|
||||
user: process.env.DB_USER!,
|
||||
password: process.env.DB_PASSWORD!,
|
||||
database: process.env.DB_NAME!,
|
||||
host: process.env.DB_HOST!,
|
||||
user: process.env.DB_USER!,
|
||||
password: process.env.DB_PASSWORD!,
|
||||
database: process.env.DB_NAME!,
|
||||
});
|
||||
|
||||
export const newProduct = async (
|
||||
name: string,
|
||||
description: string,
|
||||
price: string,
|
||||
amount: string,
|
||||
storage_location: string,
|
||||
expiry_date: string,
|
||||
bottling_date: string,
|
||||
): Promise<boolean | { success: boolean; code: string; data: null; message: string }> => {
|
||||
const newPrice = price !== "" ? price : null;
|
||||
name: string,
|
||||
description: string,
|
||||
price: string,
|
||||
amount: string,
|
||||
storage_location: string,
|
||||
expiry_date: string,
|
||||
bottling_date: string,
|
||||
): Promise<
|
||||
boolean | { success: boolean; code: string; data: null; message: string }
|
||||
> => {
|
||||
const newPrice = price !== "" ? price : null;
|
||||
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"INSERT INTO products (name, description, price, amount, storage_location, expiry_date, bottling_date) VALUES (?, ?, ?, ?, UUID_TO_BIN(?), ?, ?)",
|
||||
[name, description, newPrice, amount, storage_location, expiry_date, bottling_date],
|
||||
);
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"INSERT INTO products (name, description, price, amount, storage_location, expiry_date, bottling_date) VALUES (?, ?, ?, ?, UUID_TO_BIN(?), ?, ?)",
|
||||
[
|
||||
name,
|
||||
description,
|
||||
newPrice,
|
||||
amount,
|
||||
storage_location,
|
||||
expiry_date,
|
||||
bottling_date,
|
||||
],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP001",
|
||||
data: null,
|
||||
message: "New Product successfully created.",
|
||||
};
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP001",
|
||||
data: null,
|
||||
message: "New Product successfully created.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_CREATED);
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_CREATED);
|
||||
};
|
||||
|
||||
export const productDetails = async (uuid: string) => {
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT BIN_TO_UUID(p.uuid) AS uuid,
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT BIN_TO_UUID(p.uuid) AS uuid,
|
||||
p.name,
|
||||
p.description,
|
||||
p.price,
|
||||
@@ -55,23 +68,23 @@ export const productDetails = async (uuid: string) => {
|
||||
FROM products p
|
||||
JOIN storage_locations s ON p.storage_location = s.uuid
|
||||
WHERE p.uuid = UUID_TO_BIN(?)`,
|
||||
[uuid],
|
||||
);
|
||||
[uuid],
|
||||
);
|
||||
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP003",
|
||||
data: result[0],
|
||||
message: "Product details successfully loaded.",
|
||||
};
|
||||
}
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP003",
|
||||
data: result[0],
|
||||
message: "Product details successfully loaded.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_FOUND);
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_FOUND);
|
||||
};
|
||||
|
||||
export const allProducts = async () => {
|
||||
const [result] = await pool.query<RowDataPacket[]>(`
|
||||
const [result] = await pool.query<RowDataPacket[]>(`
|
||||
SELECT BIN_TO_UUID(p.uuid) AS uuid,
|
||||
p.name,
|
||||
p.description,
|
||||
@@ -89,52 +102,52 @@ export const allProducts = async () => {
|
||||
WHERE p.deleted = 0
|
||||
`);
|
||||
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP002",
|
||||
data: result,
|
||||
message: "All products successfully loaded.",
|
||||
};
|
||||
}
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP002",
|
||||
data: result,
|
||||
message: "All products successfully loaded.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.NO_PRODUCTS_FOUND);
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.NO_PRODUCTS_FOUND);
|
||||
};
|
||||
|
||||
export const setAmount = async (itemUUID: string, amount: number) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE products
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE products
|
||||
SET amount = ?
|
||||
WHERE uuid = UUID_TO_BIN(?)`,
|
||||
[amount, itemUUID],
|
||||
);
|
||||
[amount, itemUUID],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP004",
|
||||
data: null,
|
||||
message: "Amount successfully updated.",
|
||||
};
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP004",
|
||||
data: null,
|
||||
message: "Amount successfully updated.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_AMOUNT_NOT_UPDATED);
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_AMOUNT_NOT_UPDATED);
|
||||
};
|
||||
|
||||
export const updateItem = async (
|
||||
itemUUID: string,
|
||||
newValues: {
|
||||
name: string;
|
||||
description: string;
|
||||
price: string;
|
||||
amount: string;
|
||||
storage_location_uuid: string;
|
||||
expiry_date: string;
|
||||
bottling_date: string;
|
||||
},
|
||||
itemUUID: string,
|
||||
newValues: {
|
||||
name: string;
|
||||
description: string;
|
||||
price: string;
|
||||
amount: string;
|
||||
storage_location_uuid: string;
|
||||
expiry_date: string;
|
||||
bottling_date: string;
|
||||
},
|
||||
) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE products
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE products
|
||||
SET name = ?,
|
||||
description = ?,
|
||||
price = ?,
|
||||
@@ -143,47 +156,46 @@ export const updateItem = async (
|
||||
expiry_date = ?,
|
||||
bottling_date = ?
|
||||
WHERE uuid = UUID_TO_BIN(?);`,
|
||||
[
|
||||
newValues.name,
|
||||
newValues.description,
|
||||
newValues.price,
|
||||
newValues.amount,
|
||||
newValues.storage_location_uuid,
|
||||
newValues.expiry_date,
|
||||
newValues.bottling_date,
|
||||
itemUUID,
|
||||
],
|
||||
);
|
||||
[
|
||||
newValues.name,
|
||||
newValues.description,
|
||||
newValues.price,
|
||||
newValues.amount,
|
||||
newValues.storage_location_uuid,
|
||||
newValues.expiry_date,
|
||||
newValues.bottling_date,
|
||||
itemUUID,
|
||||
],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP005",
|
||||
data: null,
|
||||
message: "Item updated successfully.",
|
||||
};
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP005",
|
||||
data: null,
|
||||
message: "Item updated successfully.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_UPDATED);
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_UPDATED);
|
||||
};
|
||||
|
||||
export const deleteProduct = async (uuid: string) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE products
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE products
|
||||
SET deleted = 1
|
||||
WHERE uuid = UUID_TO_BIN(?);`,
|
||||
[uuid],
|
||||
);
|
||||
[uuid],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP006",
|
||||
data: null,
|
||||
message: "Product deleted successfully.",
|
||||
};
|
||||
;
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SP006",
|
||||
data: null,
|
||||
message: "Product deleted successfully.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_DELETED);
|
||||
};
|
||||
return returnErrorCode(PRODUCT_ERROR_CODE.PRODUCT_NOT_DELETED);
|
||||
};
|
||||
|
||||
@@ -1,87 +1,90 @@
|
||||
import mysql, {type ResultSetHeader, type RowDataPacket} from "mysql2/promise";
|
||||
import mysql, {
|
||||
type ResultSetHeader,
|
||||
type RowDataPacket,
|
||||
} from "mysql2/promise";
|
||||
import dotenv from "dotenv";
|
||||
import {STORAGE_ERROR_CODE} from "@stockhome/shared";
|
||||
import {returnErrorCode} from "../../../services/helperFuncs.js";
|
||||
import { STORAGE_ERROR_CODE } from "@stockhome/shared";
|
||||
import { returnErrorCode } from "../../../services/helperFuncs.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DB_HOST!,
|
||||
user: process.env.DB_USER!,
|
||||
password: process.env.DB_PASSWORD!,
|
||||
database: process.env.DB_NAME!,
|
||||
host: process.env.DB_HOST!,
|
||||
user: process.env.DB_USER!,
|
||||
password: process.env.DB_PASSWORD!,
|
||||
database: process.env.DB_NAME!,
|
||||
});
|
||||
|
||||
export const allStorages = async () => {
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
"SELECT BIN_TO_UUID(uuid) AS uuid, name, description, created_at, updated_at FROM storage_locations;",
|
||||
);
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
"SELECT BIN_TO_UUID(uuid) AS uuid, name, description, created_at, updated_at FROM storage_locations;",
|
||||
);
|
||||
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS001",
|
||||
data: result,
|
||||
message: "Successfully fetched all storage locations.",
|
||||
};
|
||||
}
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS001",
|
||||
data: result,
|
||||
message: "Successfully fetched all storage locations.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.NO_STORAGE_LOCATIONS_FOUND);
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.NO_STORAGE_LOCATIONS_FOUND);
|
||||
};
|
||||
|
||||
export const newStorage = async (name: string, description: string) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"INSERT INTO storage_locations (name, description) VALUES (?, ?)",
|
||||
[name, description],
|
||||
);
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"INSERT INTO storage_locations (name, description) VALUES (?, ?)",
|
||||
[name, description],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS002",
|
||||
data: null,
|
||||
message: "Successfully created new storage location.",
|
||||
};
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS002",
|
||||
data: null,
|
||||
message: "Successfully created new storage location.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.STORAGE_NOT_CREATED);
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.STORAGE_NOT_CREATED);
|
||||
};
|
||||
|
||||
export const updateStorage = async (
|
||||
uuid: string,
|
||||
values: { name: string; description: string },
|
||||
uuid: string,
|
||||
values: { name: string; description: string },
|
||||
) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"UPDATE storage_locations SET name = ?, description = ? WHERE uuid = UUID_TO_BIN(?);",
|
||||
[values.name, values.description, uuid],
|
||||
);
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"UPDATE storage_locations SET name = ?, description = ? WHERE uuid = UUID_TO_BIN(?);",
|
||||
[values.name, values.description, uuid],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS003",
|
||||
data: null,
|
||||
message: "Successfully updated storage location.",
|
||||
};
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS003",
|
||||
data: null,
|
||||
message: "Successfully updated storage location.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.STORAGE_NOT_UPDATED);
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.STORAGE_NOT_UPDATED);
|
||||
};
|
||||
|
||||
export const deleteStorage = async (uuid: string) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"DELETE FROM storage_locations WHERE uuid = UUID_TO_BIN(?);",
|
||||
[uuid],
|
||||
);
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"DELETE FROM storage_locations WHERE uuid = UUID_TO_BIN(?);",
|
||||
[uuid],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS004",
|
||||
data: null,
|
||||
message: "Successfully deleted storage location.",
|
||||
};
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SS004",
|
||||
data: null,
|
||||
message: "Successfully deleted storage location.",
|
||||
};
|
||||
}
|
||||
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.STORAGE_NOT_DELETED);
|
||||
};
|
||||
return returnErrorCode(STORAGE_ERROR_CODE.STORAGE_NOT_DELETED);
|
||||
};
|
||||
|
||||
@@ -1,132 +1,135 @@
|
||||
import mysql, {type ResultSetHeader, type RowDataPacket} from "mysql2/promise";
|
||||
import mysql, {
|
||||
type ResultSetHeader,
|
||||
type RowDataPacket,
|
||||
} from "mysql2/promise";
|
||||
import dotenv from "dotenv";
|
||||
import {GENERAL_ERROR_CODE, USER_ERROR_CODE} from "@stockhome/shared";
|
||||
import {returnErrorCode} from "../../../services/helperFuncs.js";
|
||||
import { GENERAL_ERROR_CODE, USER_ERROR_CODE } from "@stockhome/shared";
|
||||
import { returnErrorCode } from "../../../services/helperFuncs.js";
|
||||
import type { AuthTokenPayload } from "../../../services/tokenService";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DB_HOST!,
|
||||
user: process.env.DB_USER!,
|
||||
password: process.env.DB_PASSWORD!,
|
||||
database: process.env.DB_NAME!,
|
||||
host: process.env.DB_HOST!,
|
||||
user: process.env.DB_USER!,
|
||||
password: process.env.DB_PASSWORD!,
|
||||
database: process.env.DB_NAME!,
|
||||
});
|
||||
|
||||
export const findUser = async (username: string, password: string) => {
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
"SELECT BIN_TO_UUID(uuid) AS uuid, username, first_name, last_name, email, is_admin, is_active, last_login FROM users WHERE username = ? AND password = ?;",
|
||||
[username, password],
|
||||
);
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
"SELECT BIN_TO_UUID(uuid) AS uuid, username, first_name, last_name, email, is_admin, is_active, last_login FROM users WHERE username = ? AND password = ?;",
|
||||
[username, password],
|
||||
);
|
||||
|
||||
const userRow = result[0];
|
||||
const userRow = result[0];
|
||||
|
||||
if (!userRow) {
|
||||
return returnErrorCode(USER_ERROR_CODE.WRONG_USERNAME_PASSWORD);
|
||||
}
|
||||
if (!userRow) {
|
||||
return returnErrorCode(USER_ERROR_CODE.WRONG_USERNAME_PASSWORD);
|
||||
}
|
||||
|
||||
// Cast DB row to AuthTokenPayload for token generation / typing
|
||||
const user = userRow as unknown as AuthTokenPayload;
|
||||
// Cast DB row to AuthTokenPayload for token generation / typing
|
||||
const user = userRow as unknown as AuthTokenPayload;
|
||||
|
||||
if (!user.is_active) {
|
||||
return returnErrorCode(USER_ERROR_CODE.USER_IS_DEACTIVATED);
|
||||
}
|
||||
if (!user.is_active) {
|
||||
return returnErrorCode(USER_ERROR_CODE.USER_IS_DEACTIVATED);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
code: "SU001",
|
||||
data: user,
|
||||
message: "Successfully found user.",
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
code: "SU001",
|
||||
data: user,
|
||||
message: "Successfully found user.",
|
||||
};
|
||||
};
|
||||
|
||||
export const loginUser = async (username: string) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"UPDATE users SET last_login = NOW() WHERE username = ?;",
|
||||
[username],
|
||||
);
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
"UPDATE users SET last_login = NOW() WHERE username = ?;",
|
||||
[username],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU002",
|
||||
data: null,
|
||||
message: "Successfully logged in user.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(GENERAL_ERROR_CODE.UNEXPECTED_SERVER_ERROR);
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU002",
|
||||
data: null,
|
||||
message: "Successfully logged in user.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(GENERAL_ERROR_CODE.UNEXPECTED_SERVER_ERROR);
|
||||
}
|
||||
};
|
||||
|
||||
export const updateSettings = async (payload: {
|
||||
"app-name": string;
|
||||
currency: string;
|
||||
"app-name": string;
|
||||
currency: string;
|
||||
}) => {
|
||||
const appName = payload["app-name"];
|
||||
const currency = payload.currency;
|
||||
const appName = payload["app-name"];
|
||||
const currency = payload.currency;
|
||||
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE app_settings
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE app_settings
|
||||
SET value = CASE name
|
||||
WHEN "app-name" THEN ?
|
||||
WHEN "currency" THEN ?
|
||||
ELSE value
|
||||
END
|
||||
WHERE name IN ("app-name", "currency");`,
|
||||
[appName, currency],
|
||||
);
|
||||
[appName, currency],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU003",
|
||||
data: null,
|
||||
message: "Successfully updated settings.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(GENERAL_ERROR_CODE.UNEXPECTED_SERVER_ERROR);
|
||||
}
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU003",
|
||||
data: null,
|
||||
message: "Successfully updated settings.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(GENERAL_ERROR_CODE.UNEXPECTED_SERVER_ERROR);
|
||||
}
|
||||
};
|
||||
|
||||
export const getSettings = async () => {
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT *
|
||||
const [result] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT *
|
||||
FROM app_settings;`,
|
||||
);
|
||||
);
|
||||
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU004",
|
||||
data: result,
|
||||
message: "Successfully fetched settings.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(GENERAL_ERROR_CODE.UNEXPECTED_SERVER_ERROR);
|
||||
}
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU004",
|
||||
data: result,
|
||||
message: "Successfully fetched settings.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(GENERAL_ERROR_CODE.UNEXPECTED_SERVER_ERROR);
|
||||
}
|
||||
};
|
||||
|
||||
export const changePassword = async (
|
||||
username: string,
|
||||
currentPasswordUser: string,
|
||||
newPassword: string,
|
||||
username: string,
|
||||
currentPasswordUser: string,
|
||||
newPassword: string,
|
||||
) => {
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE users
|
||||
const [result] = await pool.query<ResultSetHeader>(
|
||||
`UPDATE users
|
||||
SET password = ?
|
||||
WHERE username = ?
|
||||
AND password = ?;`,
|
||||
[newPassword, username, currentPasswordUser],
|
||||
);
|
||||
[newPassword, username, currentPasswordUser],
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU005",
|
||||
data: null,
|
||||
message: "Successfully fetched settings.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(GENERAL_ERROR_CODE.UNEXPECTED_SERVER_ERROR);
|
||||
}
|
||||
};
|
||||
if (result.affectedRows > 0) {
|
||||
return {
|
||||
success: true,
|
||||
code: "SU005",
|
||||
data: null,
|
||||
message: "Successfully fetched settings.",
|
||||
};
|
||||
} else {
|
||||
return returnErrorCode(USER_ERROR_CODE.PASSWORD_CHANGE_FAILED);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user