Skip to content
This repository was archived by the owner on Sep 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ const defaultAddressLine2State = ""
const defaultZipCodeState = ""
const defaultCityState = ""
const defaultStateState = ""
const defaultTelephoneAreaCodeState = ""
const defaultTelephoneState = ""

export default function NewDeliveryAddressComponent() {
const [addressLine1, setAddressLine1] = useState(defaultAddressLine1State)
const [addressLine2, setAddressLine2] = useState(defaultAddressLine2State)
const [zipCode, setZipCode] = useState(defaultZipCodeState)
const [city, setCity] = useState(defaultCityState)
const [stateState, setState] = useState(defaultStateState)
const [telephoneAreaCode, setTelephoneAreaCode] = useState(defaultTelephoneAreaCodeState)
const [telephone, setTelephone] = useState(defaultTelephoneState)

const dispatch = useDispatch()
const state = useSelector(state => ({
Expand Down Expand Up @@ -59,13 +63,23 @@ export default function NewDeliveryAddressComponent() {
setState(e.target.value)
}

const handleTelephoneAreaCodeChange = e => {
setTelephoneAreaCode(e.target.value)
}

const handleTelephoneChange = e => {
setTelephone(e.target.value)
}

const handleFormSubmit = e => {
e.preventDefault()
dispatch(newUserAddress({
addressLine1,
addressLine2,
zipCode,
city,
telephoneAreaCode,
telephone,
state: stateState,
}))
}
Expand Down Expand Up @@ -94,7 +108,7 @@ export default function NewDeliveryAddressComponent() {
<div className="card">
<div className="card-body">
<div className="form-group">
<label htmlFor="addressLine1">Address Line 1:</label>
<label htmlFor="addressLine1">Address Line 1*:</label>
<input
type="text"
name="addressLine1"
Expand All @@ -116,7 +130,7 @@ export default function NewDeliveryAddressComponent() {
/>
</div>
<div className="form-group">
<label htmlFor="zipCode">Zip Code:</label>
<label htmlFor="zipCode">Zip Code*:</label>
<input
type="text"
name="zipCode"
Expand All @@ -127,7 +141,7 @@ export default function NewDeliveryAddressComponent() {
/>
</div>
<div className="form-group">
<label htmlFor="city">City:</label>
<label htmlFor="city">City*:</label>
<input
type="text"
name="city"
Expand All @@ -138,7 +152,7 @@ export default function NewDeliveryAddressComponent() {
/>
</div>
<div className="form-group">
<label htmlFor="state">State:</label>
<label htmlFor="state">State*:</label>
<input
type="text"
name="state"
Expand All @@ -148,6 +162,28 @@ export default function NewDeliveryAddressComponent() {
className="form-control"
/>
</div>
<div className="form-group">
<label htmlFor="telephoneAreaCode">Telephone Area Code:</label>
<input
type="text"
name="telephoneAreaCode"
id="telephoneAreaCode"
value={telephoneAreaCode}
onChange={handleTelephoneAreaCodeChange}
className="form-control"
/>
</div>
<div className="form-group">
<label htmlFor="telephone">Telephone*:</label>
<input
type="text"
name="telephone"
id="telephone"
value={telephone}
onChange={handleTelephoneChange}
className="form-control"
/>
</div>
</div>
<div className="card-footer">
<div className="float-end">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.addColumn(
"userAddresses",
"telephoneAreaCode",
{
type: Sequelize.STRING(6),
defaultValue: null,
after: "state",
},
{ transaction },
);
await queryInterface.addColumn(
"userAddresses",
"telephone",
{
type: Sequelize.STRING(30),
after: "telephoneAreaCode",
},
{ transaction },
);
transaction.commit();
} catch (err) {
transaction.rollback();
throw err;
}
},

async down (queryInterface, Sequelize) {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeColumn(
"userAddresses",
"telephoneAreaCode",
{ transaction },
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};
12 changes: 6 additions & 6 deletions src/models/v1/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ module.exports = (sequelize, DataTypes) => {
static getRegisterError(bodyInput) {
if (undefined === bodyInput.firstName) {
return "The first name field is missing.";
} else if (typeof bodyInput.firstName !== "string") {
} else if ("string" !== typeof bodyInput.firstName) {
return "The first name field must be of type string";
} else if (20 < bodyInput.firstName.trim().length) {
return "The first name field length must not exceed 20 characters.";
Expand All @@ -280,7 +280,7 @@ module.exports = (sequelize, DataTypes) => {

if (undefined === bodyInput.lastName) {
return "The last name field is missing.";
} else if (typeof bodyInput.lastName !== "string") {
} else if ("string" !== typeof bodyInput.lastName) {
return "The last name field must be of type string";
} else if (20 < bodyInput.lastName.trim().length) {
return "The last name field length must not exceed 20 characters.";
Expand All @@ -290,7 +290,7 @@ module.exports = (sequelize, DataTypes) => {

if (undefined === bodyInput.email) {
return "The email field is missing.";
} else if (typeof bodyInput.email !== "string") {
} else if ("string" !== typeof bodyInput.email) {
return "The email field must be of type string";
} else if (30 < bodyInput.email.length) {
return "The email field length must not exceed 30 characters.";
Expand All @@ -300,7 +300,7 @@ module.exports = (sequelize, DataTypes) => {

if (undefined === bodyInput.password) {
return "The password field is missing.";
} else if (typeof bodyInput.password !== "string") {
} else if ("string" !== typeof bodyInput.password) {
return "The password field must be of type string";
} else if (20 < bodyInput.password.length) {
return "The password field length must not exceed 20 characters.";
Expand Down Expand Up @@ -506,7 +506,7 @@ module.exports = (sequelize, DataTypes) => {
static getLoginError(bodyInput) {
if (undefined === bodyInput.email) {
return "The email field is missing.";
} else if (typeof bodyInput.email !== "string") {
} else if ("string" !== typeof bodyInput.email) {
return "The email field must be of type string";
} else if (30 < bodyInput.email.length) {
return "The email field length must not exceed 30 characters.";
Expand All @@ -516,7 +516,7 @@ module.exports = (sequelize, DataTypes) => {

if (undefined === bodyInput.password) {
return "The password field is missing.";
} else if (typeof bodyInput.password !== "string") {
} else if ("string" !== typeof bodyInput.password) {
return "The password field must be of type string";
} else if (20 < bodyInput.password.length) {
return "The password field length must not exceed 20 characters.";
Expand Down
53 changes: 51 additions & 2 deletions src/models/v1/userAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ module.exports = (sequelize, DataTypes) => {
zipCode: payload.zipCode,
city: payload.city,
state: payload.state,
telephoneAreaCode: payload.telephoneAreaCode,
telephone: payload.telephone,
createdAt: moment(payload.createdAt)
.tz(appTimezone)
.format(mysqlTimeFormat),
Expand Down Expand Up @@ -149,18 +151,48 @@ module.exports = (sequelize, DataTypes) => {
static async getNewUserAddressError(usersId, payload) {
if (!payload.addressLine1) {
return "The address line 1 field is required.";
} else if ("string" !== typeof payload.addressLine1) {
return "The address line 1 field must be of type string.";
}

if (payload.addressLine2) {
if ("string" !== typeof payload.addressLine2) {
return "The address line 2 field must be of type string.";
}
}

if (!payload.zipCode) {
return "The zip code field is required.";
} else if ("string" !== typeof payload.zipCode) {
return "The zip code field must be of type string.";
}

if (!payload.city) {
return "The city field is required.";
} else if ("string" !== typeof payload.city) {
return "The city field must be of type string.";
}

if (!payload.state) {
return "The state field is required.";
} else if ("string" !== typeof payload.state) {
return "The state field must be of type string.";
}

if (payload.telephoneAreaCode) {
if ("string" !== typeof payload.telephoneAreaCode) {
return "The telephone area code field must be of type string.";
} else if (6 < payload.telephoneAreaCode.length) {
return "The telephone area code field must not be greater than 6 characters.";
}
}

if (!payload.telephone) {
return "The telephone field is required.";
} else if ("string" !== typeof payload.telephone) {
return "The telephone field must be of type string.";
} else if (30 < payload.telephone.length) {
return "The telephone field must not be greater than 30 characters.";
}

const userAddresses = await this.
Expand Down Expand Up @@ -203,6 +235,14 @@ module.exports = (sequelize, DataTypes) => {
result.state = payload.state;
}

if (payload.telephoneAreaCode) {
result.telephoneAreaCode = payload.telephoneAreaCode;
}

if (payload.telephone) {
result.telephone = payload.telephone;
}

return result;
}

Expand All @@ -217,8 +257,8 @@ module.exports = (sequelize, DataTypes) => {
) {
try {
await sequelize.query(
`INSERT INTO ${this.getTableName()}(usersId, addressLine1, addressLine2, zipCode, city, state, createdAt, updatedAt)
VALUES(:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :createdAt, :updatedAt)`,
`INSERT INTO ${this.getTableName()}(usersId, addressLine1, addressLine2, zipCode, city, state, telephoneAreaCode, telephone, createdAt, updatedAt)
VALUES(:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :telephoneAreaCode, :telephone, :createdAt, :updatedAt)`,
{
type: sequelize.QueryTypes.INSERT,
replacements: {
Expand All @@ -227,6 +267,8 @@ module.exports = (sequelize, DataTypes) => {
zipCode: payload.zipCode,
city: payload.city,
state: payload.state,
telephoneAreaCode: payload.telephoneAreaCode,
telephone: payload.telephone,
usersId: userId,
createdAt: moment()
.utc()
Expand Down Expand Up @@ -272,6 +314,13 @@ module.exports = (sequelize, DataTypes) => {
state: {
type: DataTypes.STRING
},
telephoneAreaCode: {
type: DataTypes.STRING(6),
defaultValue: null,
},
telephone: {
type: DataTypes.STRING(30),
},
createdAt: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
Expand Down
4 changes: 3 additions & 1 deletion src/routes/api/v1/web/userAddresses/userAddresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ router.post(
res.status(status.BAD_REQUEST);
return res.json({ error: inputError });
}
return res.json({message:"Success"});

const cleanData = db.sequelize.models
.userAddress
.getNewUserAddressData({
Expand All @@ -50,6 +50,8 @@ router.post(
zipCode: req.bodyString("zipCode"),
city: req.bodyString("city"),
state: req.bodyString("state"),
telephoneAreaCode: req.bodyString("telephoneAreaCode"),
telephone: req.bodyString("telephone"),
});

const newUserAddress = await db.sequelize
Expand Down
7 changes: 5 additions & 2 deletions src/seeders/v1/20250627161105-demo-guest-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ module.exports = {
);
const usersId = userInsertResult[0];
await queryInterface.sequelize.query(
`INSERT INTO userAddresses(usersId, addressLine1, addressLine2, zipCode, city, state, createdAt, updatedAt)
VALUES (:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :createdAt, :updatedAt)`,
`INSERT INTO userAddresses(usersId, addressLine1, addressLine2, zipCode, city, state, telephone, createdAt, updatedAt)
VALUES (:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :telephone, :createdAt, :updatedAt)`,
{
replacements: {
addressLine1: faker.location.streetAddress(),
addressLine2: faker.location.secondaryAddress(),
zipCode: faker.location.zipCode(),
city: faker.location.city(),
state: faker.location.state(),
telephone: faker.phone.number({
international: true,
}),
createdAt: moment().utc().format(mysqlTimeFormat),
updatedAt: moment().utc().format(mysqlTimeFormat),
usersId,
Expand Down
7 changes: 5 additions & 2 deletions src/seeders/v1/20250627161357-demo-admin-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ module.exports = {
);
const usersId = userInsertResult[0];
await queryInterface.sequelize.query(
`INSERT INTO userAddresses(usersId, addressLine1, addressLine2, zipCode, city, state, createdAt, updatedAt)
VALUES (:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :createdAt, :updatedAt)`,
`INSERT INTO userAddresses(usersId, addressLine1, addressLine2, zipCode, city, state, telephone, createdAt, updatedAt)
VALUES (:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :telephone, :createdAt, :updatedAt)`,
{
replacements: {
addressLine1: faker.location.streetAddress(),
addressLine2: faker.location.secondaryAddress(),
zipCode: faker.location.zipCode(),
city: faker.location.city(),
state: faker.location.state(),
telephone: faker.phone.number({
international: true,
}),
createdAt: moment().utc().format(mysqlTimeFormat),
updatedAt: moment().utc().format(mysqlTimeFormat),
usersId,
Expand Down
7 changes: 5 additions & 2 deletions src/seeders/v1/20250705172336-demo-guest-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ module.exports = {
);
const usersId = userInsertResult[0];
await queryInterface.sequelize.query(
`INSERT INTO userAddresses(usersId, addressLine1, addressLine2, zipCode, city, state, createdAt, updatedAt)
VALUES (:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :createdAt, :updatedAt)`,
`INSERT INTO userAddresses(usersId, addressLine1, addressLine2, zipCode, city, state, telephone, createdAt, updatedAt)
VALUES (:usersId, :addressLine1, :addressLine2, :zipCode, :city, :state, :telephone, :createdAt, :updatedAt)`,
{
replacements: {
addressLine1: faker.location.streetAddress(),
addressLine2: faker.location.secondaryAddress(),
zipCode: faker.location.zipCode(),
city: faker.location.city(),
state: faker.location.state(),
telephone: faker.phone.number({
international: true,
}),
createdAt: moment().utc().format(mysqlTimeFormat),
updatedAt: moment().utc().format(mysqlTimeFormat),
usersId,
Expand Down