company name
parent
c9f0054b59
commit
3feda45f74
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response } from "express";
|
||||
import Store from "../models/store";
|
||||
import { getUserSession } from "../utils/utils";
|
||||
import { isCompanyNameValid } from "../validator/validator";
|
||||
|
||||
export async function GetStore(req: Request, res: Response) {
|
||||
try {
|
||||
|
@ -51,6 +52,12 @@ export async function UpdateStore(req: Request, res: Response) {
|
|||
const { storeId } = req.params;
|
||||
const { name, phoneNumber, email, address } = req.body;
|
||||
|
||||
// validate request
|
||||
|
||||
if (!isCompanyNameValid(name)) {
|
||||
return res.status(400).send({ err: "invalid request" });
|
||||
}
|
||||
|
||||
// check if requester is the store owner
|
||||
|
||||
const userSession = await getUserSession(req);
|
||||
|
|
|
@ -3,6 +3,7 @@ import logger from "../logger/logger";
|
|||
import User from "../models/user";
|
||||
import {
|
||||
isAccountNameValid,
|
||||
isCompanyNameValid,
|
||||
isLanguageCodeValid,
|
||||
isPasswordValid,
|
||||
isUsernameValid,
|
||||
|
@ -31,15 +32,18 @@ import Feedback from "../models/feedback";
|
|||
|
||||
export async function SignUp(req: Request, res: Response) {
|
||||
try {
|
||||
let { username, accountName, password, language, rememberMe } = req.body;
|
||||
let { companyName, username, accountName, password, language, rememberMe } =
|
||||
req.body;
|
||||
|
||||
// validate request
|
||||
|
||||
if (
|
||||
!companyName ||
|
||||
!username ||
|
||||
!accountName ||
|
||||
!password ||
|
||||
!language ||
|
||||
!isCompanyNameValid(companyName) ||
|
||||
!isUsernameValid(username) ||
|
||||
!isAccountNameValid(accountName) ||
|
||||
!isLanguageCodeValid(language) ||
|
||||
|
@ -81,7 +85,7 @@ export async function SignUp(req: Request, res: Response) {
|
|||
Store.create({
|
||||
store_id: newStoreId(),
|
||||
owner_user_id: userId,
|
||||
name: username,
|
||||
name: companyName,
|
||||
calendar_max_future_booking_days: CALENDAR_MAX_FUTURE_BOOKING_DAYS,
|
||||
calendar_min_earliest_booking_time: CALENDAR_MIN_EARLIEST_BOOKING_TIME,
|
||||
calendar_max_service_duration: CALENDAR_MAX_SERVICE_DURATION,
|
||||
|
|
|
@ -38,6 +38,9 @@ export const CALENDAR_MIN_EARLIEST_BOOKING_TIME = 15; // 15 minutes
|
|||
export const CALENDAR_USING_PRIMARY_CALENDAR = false;
|
||||
export const CALENDAR_MAX_SERVICE_DURATION = 1440; // 24 hours in minutes
|
||||
|
||||
export const COMPANY_NAME_MIN_LENGTH = 3;
|
||||
export const COMPANY_NAME_MAX_LENGTH = 64;
|
||||
|
||||
// applied to all new created users or employees
|
||||
export const USER_ANALYTICS_ENABLED_DEFAULT = true;
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ import {
|
|||
VALID_LANGUAGE_CODES,
|
||||
FEEDBACK_MAX_LENGTH,
|
||||
FEEDBACK_MIN_LENGTH,
|
||||
COMPANY_NAME_MIN_LENGTH,
|
||||
COMPANY_NAME_MAX_LENGTH,
|
||||
} from "../utils/constants";
|
||||
import User from "../models/user";
|
||||
|
||||
|
@ -123,3 +125,10 @@ export function isFeedbackValid(feedback: string) {
|
|||
feedback.length <= FEEDBACK_MAX_LENGTH
|
||||
);
|
||||
}
|
||||
|
||||
export function isCompanyNameValid(companyName: string) {
|
||||
return (
|
||||
companyName.length >= COMPANY_NAME_MIN_LENGTH &&
|
||||
companyName.length <= COMPANY_NAME_MAX_LENGTH
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue