diff --git a/controllers/businessController.js b/controllers/businessController.js index 34c17e1..872cd5c 100644 --- a/controllers/businessController.js +++ b/controllers/businessController.js @@ -5,20 +5,26 @@ exports.registerBusiness = async (req, res) => { try { const { businessName, - businessEmail, - categoryId, + businessEmail, + categoryId, businessAddress, businessPhone, websiteUrl, latitude, - longitude + longitude, + openingTime, + closingTime, + businessLicenseNumber } = req.body; - + // Convert latitude and longitude to Float const latitudeFloat = parseFloat(latitude); const longitudeFloat = parseFloat(longitude); - + // Convert businessLicenseNumber to Integer if it's provided + const businessLicenseNumberInt = businessLicenseNumber ? parseInt(businessLicenseNumber, 10) : undefined; + + // Validate that the categoryId exists in the database const category = await prisma.category.findUnique({ where: { id: categoryId } }); @@ -27,7 +33,7 @@ exports.registerBusiness = async (req, res) => { return res.status(400).json({ message: "Invalid category ID" }); } - + // Validate that the user exists in the database const user = await prisma.user.findUnique({ where: { email: businessEmail } }); @@ -39,52 +45,48 @@ exports.registerBusiness = async (req, res) => { const newBusiness = await prisma.business.create({ data: { businessName, - ownerId: user.id, - categoryId, + ownerId: user.id, + categoryId, businessEmail, businessAddress, businessPhone, websiteUrl, - latitude: latitudeFloat, - longitude: longitudeFloat, - }, + latitude: latitudeFloat, + longitude: longitudeFloat, + openingTime, // Save opening time + closingTime, // Save closing time + businessLicenseNumber: businessLicenseNumberInt // Save business license number + } }); - res.status(201).json(newBusiness); } catch (error) { - res.status(500).json({ error: error.message }); } }; exports.getAllBusinesses = async (req, res) => { try { - const businesses = await prisma.business.findMany({ include: { - category: true, + category: true, }, }); - res.status(200).json(businesses); } catch (error) { - res.status(500).json({ error: error.message }); } }; - exports.getBusinessById = async (req, res) => { const { id } = req.params; try { - const business = await prisma.business.findUnique({ where: { id }, include: { - category: true, + category: true, }, }); @@ -92,49 +94,38 @@ exports.getBusinessById = async (req, res) => { return res.status(404).json({ message: 'Business not found' }); } - res.status(200).json(business); } catch (error) { - res.status(500).json({ error: error.message }); } }; - - exports.getCategoryById = async (req, res) => { const { categoryId } = req.params; try { - if (!isValidUUID(categoryId)) { return res.status(400).json({ message: "Invalid category ID format" }); } - const category = await prisma.category.findUnique({ where: { id: categoryId }, }); - if (!category) { return res.status(404).json({ message: "Category not found" }); } - res.status(200).json(category); } catch (error) { - res.status(500).json({ error: error.message }); } }; + exports.getBusinessesByCategoryId = async (req, res) => { const { categoryId } = req.params; - console.log('Received categoryId:', categoryId); - try { - if (!isValidUUID(categoryId)) { return res.status(400).json({ message: "Invalid category ID format" }); } @@ -147,33 +138,26 @@ exports.getBusinessesByCategoryId = async (req, res) => { return res.status(404).json({ message: "Category not found" }); } - const businesses = await prisma.business.findMany({ where: { categoryId }, include: { - category: true, + category: true, }, }); - if (businesses.length === 0) { return res.status(404).json({ message: "No businesses found for this category" }); } res.status(200).json(businesses); } catch (error) { - res.status(500).json({ error: error.message }); } }; - - - exports.getBusinessesBySearchCriteria = async (req, res) => { - const { name, address, service } = req.query; + const { name, address, service } = req.query; try { - const searchConditions = {}; if (name) { @@ -183,7 +167,6 @@ exports.getBusinessesBySearchCriteria = async (req, res) => { }; } - if (address) { searchConditions.businessAddress = { contains: address, @@ -205,41 +188,30 @@ exports.getBusinessesBySearchCriteria = async (req, res) => { const businesses = await prisma.business.findMany({ where: searchConditions, include: { - category: true, - services: true, + category: true, + services: true, }, }); - if (businesses.length === 0) { return res.status(404).json({ message: "No businesses found matching the search criteria" }); } - res.status(200).json(businesses); } catch (error) { - res.status(500).json({ error: error.message }); } }; - - const isValidUUID = (id) => { const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; return uuidRegex.test(id); }; -/// controllers/businessController.js -/** - * Delete a business by ID - * This function deletes a business identified by its ID. - */ exports.deleteBusinessById = async (req, res) => { const { id } = req.params; try { - // Check if the business exists const business = await prisma.business.findUnique({ where: { id }, }); @@ -248,23 +220,16 @@ exports.deleteBusinessById = async (req, res) => { return res.status(404).json({ message: 'Business not found' }); } - // Delete the business await prisma.business.delete({ where: { id }, }); - // Respond with a success message res.status(200).json({ message: 'Business deleted successfully' }); } catch (error) { - // Handle errors and respond with an appropriate message res.status(500).json({ error: error.message }); } }; -/** - * Update a business by ID - * This function updates the details of a business identified by its ID. - */ exports.updateBusinessById = async (req, res) => { const { id } = req.params; const { @@ -276,14 +241,15 @@ exports.updateBusinessById = async (req, res) => { websiteUrl, latitude, longitude, + openingTime, + closingTime, + businessLicenseNumber } = req.body; try { - // Convert latitude and longitude to Float if provided const latitudeFloat = latitude ? parseFloat(latitude) : undefined; const longitudeFloat = longitude ? parseFloat(longitude) : undefined; - // Validate the categoryId if provided if (categoryId) { const category = await prisma.category.findUnique({ where: { id: categoryId } @@ -294,7 +260,6 @@ exports.updateBusinessById = async (req, res) => { } } - // Check if the business exists const business = await prisma.business.findUnique({ where: { id }, }); @@ -303,7 +268,6 @@ exports.updateBusinessById = async (req, res) => { return res.status(404).json({ message: 'Business not found' }); } - // Update the business with the provided data const updatedBusiness = await prisma.business.update({ where: { id }, data: { @@ -315,13 +279,14 @@ exports.updateBusinessById = async (req, res) => { websiteUrl, latitude: latitudeFloat, longitude: longitudeFloat, + openingTime, + closingTime, + businessLicenseNumber: businessLicenseNumber ? parseInt(businessLicenseNumber, 10) : undefined }, }); - // Respond with the updated business details res.status(200).json(updatedBusiness); } catch (error) { - // Handle errors and respond with an appropriate message res.status(500).json({ error: error.message }); } }; diff --git a/manual.md b/manual.md new file mode 100644 index 0000000..d4efae3 --- /dev/null +++ b/manual.md @@ -0,0 +1,252 @@ +# API Manual for Business Directory Project + +## Overview +This manual provides detailed information about the API endpoints available in the Business Directory application. It includes descriptions, required fields, and example requests for both backend and frontend developers. + +--- + +## User Management APIs + +### 1. **User Registration** +- **Endpoint**: `/api/users/register` +- **Method**: `POST` +- **Purpose**: Register a new user. + +#### Required Fields +| Field | Description | +|------------|--------------------------------------| +| `username` | The unique username for the user. | +| `email` | The user's email address. | +| `password` | The user's password. | +| `firstname`| The user's first name. | +| `lastname` | The user's last name. | + +#### Example Request +```json +{ + "username": "john_doe", + "email": "john@example.com", + "password": "securepassword", + "firstname": "John", + "lastname": "Doe" +} +``` +### 2. User Login + +- **Endpoint**: `/api/users/login` +- **Method**: `POST` +- **Purpose**: Log in an existing user. + +#### Required Fields + +| Field | Description | +|----------|------------------------------| +| `email` | The user's email address. | +| `password` | The user's password. | + +#### Example Request + +```json +POST /api/users/login +Content-Type: application/json + +{ + "email": "testuser@example.com", + "password": "Password@123" +} + +``` +### 3. Get User Profile + +- **Endpoint**: `/api/users/profile` +- **Method**: `GET` +- **Purpose**: Retrieve the current user's profile. + +#### Usage + +- **Authentication**: Requires an authentication token. + +#### Example Request + +```http +GET /api/users/profile +Authorization: Bearer YOUR_AUTH_TOKEN +``` +### 4. Update User Profile + +- **Endpoint**: `/api/users/profile` +- **Method**: `PUT` +- **Purpose**: Update the user's profile information. +- **Authentication**: Requires an authentication token. +- **Required Fields**: +firstname: The updated first name. +lastname: The updated last name. +email: The updated email address. +#### Example Request + +```json +PUT /api/users/profile +Authorization: Bearer YOUR_JWT_TOKEN +Content-Type: application/json + +{ + "firstname": "Updated", + "lastname": "User", + "email": "updateduser@example.com" +} + +``` +### 5. Delete User Profile + +- **Endpoint**: `/api/users/profile` +- **Method**: `DELETE` +- **Purpose**: Delete the current user's profile. + +#### Usage + +- **Authentication**: Requires an authentication token. + +#### Example Request + +```http +DELETE /api/users/profile +Authorization: Bearer YOUR_AUTH_TOKEN +``` +## Business Directory APIs + +### 1. Register Business + +- **Endpoint**: `/api/businesses/register` +- **Method**: `POST` +- **Purpose**: Register a new business. + +#### Required Fields + +| Field | Description | +|-------------------|--------------------------------------------------| +| `businessName` | The name of the business. | +| `businessEmail` | The business owner email address this help as to find the owner . | +| `categoryId` | The ID of the category to which the business belongs. | +| `businessAddress` | The physical address of the business. | +| `businessPhone` | The contact phone number for the business. | +| `websiteUrl` | The business's website URL. | +| `latitude` | The latitude coordinate of the business location.| +| `longitude` | The longitude coordinate of the business location.| + +#### Example Request + +```json +POST /api/businesses/register +Authorization: Bearer YOUR_JWT_TOKEN +Content-Type: application/json + +{ + "businessName": "Test Business", + "categoryId": "CATEGORY_ID_HERE", + "businessEmail": "business@example.com", + "businessAddress": "123 Business St", + "businessPhone": "123-456-7890", + "websiteUrl": "http://example.com", + "latitude": 40.7128, + "longitude": -74.0060 +} + +``` + + +### 2. Get All Businesses + +- **Endpoint**: `/api/businesses` +- **Method**: `GET` +- **Purpose**: Retrieve a list of all registered businesses. + +#### Example Request + +```http +GET /api/businesses +``` +### 3. Get Business by ID + +- **Endpoint**: `/api/businesses/{BUSINESS_ID}` +- **Method**: `GET` +- **Purpose**: Retrieve details of a specific business by its ID. + +#### Example Request + +```http +GET /api/businesses/123 +``` +### 4. Update Business + +- **Endpoint**: `/api/businesses/business/{BUSINESS_ID}` +- **Method**: `PUT` +- **Purpose**: Update the details of an existing business. +- **Required Fields**: + - *businessName*: The updated name of the business. + - *businessEmail*: The updated email address. + - *businessAddress*: The updated address. + - *businessPhone*: The updated phone number. + +#### Example Request + +```json +PUT /api/businesses/123 +Authorization: Bearer YOUR_JWT_TOKEN +Content-Type: application/json + +{ + "businessName": "Updated Business Name", + "businessEmail": "updated@example.com", + "businessAddress": "456 New Address", + "businessPhone": "987-654-3210" +} + +``` +### 5. Delete Business + +- **Endpoint**: `/api/businesses/business/{BUSINESS_ID}` +- **Method**: `DELETE` +- **Purpose**: Delete a specific business by its ID. +- **Authentication**: Requires an authentication token. +#### Example Request + +```http +DELETE /api/businesses/123 +Authorization: Bearer YOUR_JWT_TOKEN + +``` +### 6. Get Businesses by Category ID + +- **Endpoint**: `/api/businesses/businesses/category/{CATEGORY_ID}` +- **Method**: `GET` +- **Purpose**: Retrieve businesses belonging to a specific category. + +#### Example Request + +```http +GET /api/businesses/businesses/category/1 +``` +### 7. Get Businesses by Search Criteria + +- **Endpoint**: `/api/businesses/search` +- **Method**: `GET` +- **Purpose**: Search for businesses based on various criteria (e.g., name, location). + +#### Example Request + +```http +GET /api/businesses/businesses/search?name=Test Busiyu&address=123 Business St +``` + +### 8,Get Category Name by Category ID + +- **Endpoint**: `http://localhost:5000/api/businesses/categories/{CATEGORY_ID}` +- **Method**: `GET` +- **Purpose**: Retrieve the name of a category by its ID. + +#### Example Request + +```http +GET http://localhost:5000/api/businesses/categories/1 +``` + diff --git a/package-lock.json b/package-lock.json index 1304457..569eb8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "dotenv": "^16.4.5", "express": "^4.19.2", "jsonwebtoken": "^9.0.2", + "multer": "^1.4.5-lts.1", "nodemailer": "^6.9.14", "nodemon": "^3.1.4", "pg": "^8.12.0" @@ -154,6 +155,12 @@ "node": ">= 8" } }, + "node_modules/append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", + "license": "MIT" + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -264,6 +271,23 @@ "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", "license": "BSD-3-Clause" }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "license": "MIT" + }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -419,6 +443,21 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "node_modules/concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "engines": [ + "node >= 0.8" + ], + "license": "MIT", + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -462,6 +501,12 @@ "dev": true, "license": "MIT" }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "license": "MIT" + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -1124,6 +1169,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "license": "MIT" + }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -1331,6 +1382,27 @@ "node": ">=10" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/mocha": { "version": "10.7.3", "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.7.3.tgz", @@ -1405,6 +1477,24 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "license": "MIT" }, + "node_modules/multer": { + "version": "1.4.5-lts.1", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.1.tgz", + "integrity": "sha512-ywPWvcDMeH+z9gQq5qYHCCy+ethsk4goepZ45GLD63fOu0YcNecQxi64nDs3qluZB+murG3/D4dJ7+dGctcCQQ==", + "license": "MIT", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.0.0", + "concat-stream": "^1.5.2", + "mkdirp": "^0.5.4", + "object-assign": "^4.1.1", + "type-is": "^1.6.4", + "xtend": "^4.0.0" + }, + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -1519,6 +1609,15 @@ "node": ">=0.10.0" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", @@ -1770,6 +1869,12 @@ "fsevents": "2.3.3" } }, + "node_modules/process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "license": "MIT" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -1837,6 +1942,27 @@ "node": ">= 0.8" } }, + "node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "license": "MIT", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/readable-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -2022,6 +2148,29 @@ "node": ">= 0.8" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, + "node_modules/string_decoder/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -2194,6 +2343,12 @@ "node": ">= 0.6" } }, + "node_modules/typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", + "license": "MIT" + }, "node_modules/undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", @@ -2208,6 +2363,12 @@ "node": ">= 0.8" } }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT" + }, "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", diff --git a/package.json b/package.json index 6a0a526..c85b3df 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dotenv": "^16.4.5", "express": "^4.19.2", "jsonwebtoken": "^9.0.2", + "multer": "^1.4.5-lts.1", "nodemailer": "^6.9.14", "nodemon": "^3.1.4", "pg": "^8.12.0" diff --git a/prisma/migrations/20240904204438_update_business_license_number/migration.sql b/prisma/migrations/20240904204438_update_business_license_number/migration.sql new file mode 100644 index 0000000..832bd96 --- /dev/null +++ b/prisma/migrations/20240904204438_update_business_license_number/migration.sql @@ -0,0 +1,19 @@ +/* + Warnings: + + - Made the column `websiteUrl` on table `Business` required. This step will fail if there are existing NULL values in that column. + - Made the column `latitude` on table `Business` required. This step will fail if there are existing NULL values in that column. + - Made the column `longitude` on table `Business` required. This step will fail if there are existing NULL values in that column. + +*/ +-- DropIndex +DROP INDEX "Business_businessEmail_key"; + +-- DropIndex +DROP INDEX "Business_businessPhone_key"; + +-- AlterTable +ALTER TABLE "Business" ADD COLUMN "businessLicenseNumber" INTEGER, +ALTER COLUMN "websiteUrl" SET NOT NULL, +ALTER COLUMN "latitude" SET NOT NULL, +ALTER COLUMN "longitude" SET NOT NULL; diff --git a/prisma/migrations/20240905205505_update_business_model/migration.sql b/prisma/migrations/20240905205505_update_business_model/migration.sql new file mode 100644 index 0000000..41592d0 --- /dev/null +++ b/prisma/migrations/20240905205505_update_business_model/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - Added the required column `closingTime` to the `Business` table without a default value. This is not possible if the table is not empty. + - Added the required column `openingTime` to the `Business` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "Business" ADD COLUMN "closingTime" TEXT NOT NULL, +ADD COLUMN "openingTime" TEXT NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6c4a440..d990e11 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -28,16 +28,19 @@ model User { // Business model model Business { - id String @id @default(uuid()) - businessName String - ownerId String - categoryId String - businessEmail String @unique - businessAddress String - businessPhone String @unique - websiteUrl String? - latitude Float? - longitude Float? + id String @id @default(uuid()) + businessName String + ownerId String + categoryId String + businessEmail String + businessAddress String + businessPhone String + websiteUrl String + latitude Float + longitude Float + openingTime String // Ensure this field exists + closingTime String + businessLicenseNumber Int? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt owner User @relation("UserBusinesses", fields: [ownerId], references: [id])