Skip to content

Commit

Permalink
Merge pull request #172 from Vitruveo/feat/public-route-to-find-store
Browse files Browse the repository at this point in the history
Feat/public route to find store
  • Loading branch information
m-paice authored Jan 17, 2025
2 parents 0712bb5 + 9c4004e commit d3ca4ac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/features/stores/controller/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,36 @@ route.get('/validate/:hash', async (req, res) => {
}
});

route.get('/:subdomain', async (req, res) => {
try {
const { subdomain } = req.params;

const store = await model.findStoresBySubdomain(subdomain);

if (!store) {
res.status(404).json({
code: 'vitruveo.studio.api.stores.find.failed',
message: 'Store not found',
transaction: nanoid(),
} as APIResponse);
return;
}

res.status(200).json({
code: 'vitruveo.studio.api.stores.find.success',
message: 'Store found',
data: store,
transaction: nanoid(),
} as APIResponse);
} catch (error) {
logger('Find stores failed: %O', error);
res.status(500).json({
code: 'vitruveo.studio.api.stores.find.failed',
message: `Find failed: ${error}`,
args: error,
transaction: nanoid(),
} as APIResponse);
}
});

export { route };
4 changes: 2 additions & 2 deletions src/features/stores/controller/rules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nanoid } from 'nanoid';
import { NextFunction, Request, Response } from 'express';
import axios from 'axios';
import { APIResponse } from '../../../services';
import {
schemaValidationArtworks,
Expand All @@ -8,7 +9,6 @@ import {
schemaValidationStepName,
} from './schemas';
import { FrameworkSchema } from '../model';
import axios from 'axios';
import { GENERAL_STORAGE_URL } from '../../../constants';

export const validateBodyForCreateStores = async (
Expand All @@ -28,7 +28,7 @@ export const validateBodyForCreateStores = async (

try {
req.body = schemaValidationForCreateStores.parse(req.body);
const url: string = req.body.organization.url;
const { url } = req.body.organization;

if (!url.match(/^[a-zA-Z0-9-]+$/) || url.length < 4) {
res.status(400).json({
Expand Down
3 changes: 3 additions & 0 deletions src/features/stores/model/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const findStoresByHash = (hash: string) => stores().findOne({ hash });
export const findStoresById = (id: string) =>
stores().findOne({ _id: new ObjectId(id) });

export const findStoresBySubdomain = (subdomain: string) =>
stores().findOne({ 'organization.url': subdomain });

export const updateStores = ({ id, data }: UpdateStoresParams) => {
const envelope = StoresSchema.parse(data);

Expand Down

0 comments on commit d3ca4ac

Please sign in to comment.