fix: signup password validation

feat: add search by brands (WIP)
This commit is contained in:
Gérard Le Cloerec 2021-04-09 10:19:47 +02:00
parent 15d740e85f
commit 164db10e08
8 changed files with 81 additions and 70 deletions

View File

@ -43,6 +43,7 @@ interface Props {
pages?: Page[]
commerceFeatures: Record<string, boolean>
}
categories: any[]
}
const Layout: FC<Props> = ({

View File

@ -5,7 +5,7 @@ import { Searchbar, UserNav } from '@components/common'
import NavbarRoot from './NavbarRoot'
import s from './Navbar.module.css'
const Navbar: FC = () => (
const Navbar: FC = ({ categories }: any) => (
<NavbarRoot>
<Container>
<div className="relative flex flex-row justify-between py-4 align-center md:py-6">
@ -19,7 +19,7 @@ const Navbar: FC = () => (
<Link href="/search">
<a className={s.link}>All</a>
</Link>
<Link href="/search?q=clothes">
{/* <Link href="/search?q=clothes">
<a className={s.link}>Clothes</a>
</Link>
<Link href="/search?q=accessories">
@ -27,7 +27,7 @@ const Navbar: FC = () => (
</Link>
<Link href="/search?q=shoes">
<a className={s.link}>Shoes</a>
</Link>
</Link> */}
</nav>
</div>

View File

@ -1,6 +1,4 @@
import { Product } from '@commerce/types'
import { normalizeProduct } from '../../../lib/normalize'
import getAllProducts from '../../../product/get-all-products'
import type { ProductsHandlers } from '../products'
const SORT: { [key: string]: string | undefined } = {
@ -22,7 +20,9 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
}
let sort = {}
if (search) filter['$text'] = { $search: search }
if (search) {
filter['$text'] = { $search: search }
}
if (category) {
const cat: any = await config.storeApiFetch('/v2/category', {
@ -44,13 +44,29 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
const productIds: string[] = cat.productsList
.filter((p: any) => p.checked)
.map((p: any) => p.id)
filter = {
$and: [
filter,
{
_id: { $in: productIds },
},
],
if (filter['$and']) {
filter['$and'].push({
_id: { $in: productIds },
})
} else {
filter = {
$and: [
filter,
{
_id: { $in: productIds },
},
],
}
}
}
if (brand) {
if (filter['$and']) {
filter['$and'].push({ 'trademark.code': brand })
} else {
filter = {
$and: [filter, { 'trademark.code': brand }],
}
}
}
@ -61,8 +77,6 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
if (sortValue && direction) {
switch (sortValue) {
case 'latest':
// 'desc'
console.log(`sort by ${sortValue} not implemented`)
case 'trending':
// 'desc'
console.log(`sort by ${sortValue} not implemented`)
@ -72,23 +86,6 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
}
}
}
console.log(
JSON.stringify({
lang: 'en',
PostBody: {
filter,
structure: {
canonical: 1,
reviews: 1,
stock: 1,
universe: 1,
},
sort,
page: 1,
limit: LIMIT,
},
})
)
const { datas } = await config.storeApiFetch('/v2/products', {
method: 'POST',
body: JSON.stringify({

View File

@ -14,7 +14,6 @@ const checkoutApi: AquilacmsApiHandler<any> = async (req, res, config) => {
const { cookies } = req
const cartId = cookies[config.cartCookie]
const token = cookies[config.customerCookie]
console.log(config.customerCookie, cookies)
try {
if (!cartId) {
@ -22,9 +21,15 @@ const checkoutApi: AquilacmsApiHandler<any> = async (req, res, config) => {
return
}
if (!token)
return res.status(401).json({
data: null,
errors: [{ message: 'You need to be logged in to continue' }],
})
if (fullCheckout) {
const { data } = await config.storeApiFetch(
`/v/carts/${cartId}/redirect_urls`,
`/v3/carts/${cartId}/redirect_urls`,
{
method: 'POST',
}

View File

@ -13,7 +13,7 @@ const signup: SignupHandlers['signup'] = async ({
lastName: Joi.string().min(1),
email: Joi.string().email({ tlds: false }),
password: Joi.string().pattern(
new RegExp('^(?=.*d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^wd:])([^s]){6,}$')
new RegExp(/^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\d\s:])([^\s]){6,}$/)
),
})

View File

@ -33,20 +33,6 @@ async function getAllPages({
preview?: boolean
} = {}): Promise<GetAllPagesResult> {
config = getConfig(config)
// const { datas } = await config.storeApiFetch('/v2/categories', {
// method: 'POST',
// body: JSON.stringify({
// lang: 'en',
// PostBody: {
// filter: {
// action: 'page',
// },
// limit: 10,
// page: 1,
// },
// }),
// })
const { datas }: { datas: AquilacmsStatic[] } = await config.storeApiFetch(
'/v2/statics',
{

View File

@ -23,34 +23,57 @@ async function getSiteInfo({
config?: AquilacmsConfig
preview?: boolean
} = {}): Promise<GetSiteInfoResult> {
// TODO:
config = getConfig(config)
const { datas } = await config.storeApiFetch('/v2/categories', {
method: 'POST',
body: JSON.stringify({
lang: 'en',
PostBody: {
filter: {
action: 'catalog',
const [p1, p2]: { datas: any[]; count: number }[] = await Promise.all([
config.storeApiFetch('/v2/categories', {
method: 'POST',
body: JSON.stringify({
lang: 'en',
PostBody: {
filter: {
action: 'catalog',
},
limit: 10,
page: 1,
structure: {
code: 1,
slug: 1,
name: 1,
},
},
limit: 10,
page: 1,
structure: {
code: 1,
slug: 1,
name: 1,
},
},
}),
}),
})
config.storeApiFetch('/v2/trademarks', {
method: 'POST',
body: JSON.stringify({
PostBody: {
limit: 10,
structure: {
_id: 1,
name: 1,
code: 1,
},
},
}),
}),
])
const categories = p1.datas
const brands = p2.datas
return {
categories: datas.map((c: any) => ({
categories: categories.map((c: any) => ({
path: c.slug['en'],
entityId: c._id,
name: c.name,
})),
brands: [],
brands: brands.map((b: any) => ({
node: {
entityId: b._id,
path: `brands/${b.code}`,
name: b.name,
},
})),
}
}

View File

@ -26,8 +26,7 @@ export const handler: SWRHook<
if (search) url.searchParams.set('search', search)
if (categoryId) url.searchParams.set('category', String(categoryId))
if (Number.isInteger(brandId))
url.searchParams.set('brand', String(brandId))
if (brandId) url.searchParams.set('brand', String(brandId))
if (sort) url.searchParams.set('sort', sort)
return fetch({