# ZAP Integration - Database Setup Instructions

## Add ZAP Supplier to Database

You need to manually add a new Supplier document to your MongoDB database in the `suppliers` collection:

### Option 1: MongoDB Compass or Studio 3T

Connect to your database and insert the following document into the `suppliers` collection:

```json
{
  "name": "ZAP Group",
  "supplierNumber": "SUP-007",
  "displayNameHe": "ZAP",
  "displayNameEn": "ZAP",
  "integrationType": "api",
  "integrationKey": "zap",
  "requiresApiKey": true,
  "requiresStoreId": false,
  "requiresCompanyName": false,
  "orderSource": 5,
  "isActive": true,
  "supportsAutoSync": true,
  "supportsShipping": true,
  "configModule": "zap",
  "hasClubs": false,
  "createdAt": "2026-03-09T00:00:00.000Z",
  "updatedAt": "2026-03-09T00:00:00.000Z"
}
```

### Option 2: MongoDB Shell

Connect to your database and run:

```javascript
db.suppliers.insertOne({
  name: "ZAP Group",
  supplierNumber: "SUP-007",
  displayNameHe: "ZAP",
  displayNameEn: "ZAP",
  integrationType: "api",
  integrationKey: "zap",
  requiresApiKey: true,
  requiresStoreId: false,
  requiresCompanyName: false,
  orderSource: 5,
  isActive: true,
  supportsAutoSync: true,
  supportsShipping: true,
  configModule: "zap",
  hasClubs: false,
  createdAt: new Date("2026-03-09"),
  updatedAt: new Date("2026-03-09")
});
```

### Option 3: Node.js Script

Create a temporary script file `add-zap-supplier.js`:

```javascript
require('dotenv').config();
const mongoose = require('mongoose');
const Supplier = require('./models/Supplier');

async function addZapSupplier() {
  try {
    await mongoose.connect(process.env.MONGO_URI);
    console.log('Connected to MongoDB');

    const zapSupplier = await Supplier.create({
      name: "ZAP Group",
      supplierNumber: "SUP-007",
      displayNameHe: "ZAP",
      displayNameEn: "ZAP",
      integrationType: "api",
      integrationKey: "zap",
      requiresApiKey: true,
      requiresStoreId: false,
      requiresCompanyName: false,
      orderSource: 5,
      isActive: true,
      supportsAutoSync: true,
      supportsShipping: true,
      configModule: "zap",
      hasClubs: false
    });

    console.log('✅ ZAP Supplier created:', zapSupplier);
    process.exit(0);
  } catch (error) {
    console.error('❌ Error:', error);
    process.exit(1);
  }
}

addZapSupplier();
```

Run it with: `node add-zap-supplier.js`

## Verify Installation

After adding the Supplier document, verify it exists:

```javascript
db.suppliers.findOne({ integrationKey: "zap" })
```

You should see the ZAP supplier document with all the fields.

## Configure User Integration

To enable ZAP for a specific user, update their User document:

```javascript
db.users.updateOne(
  { _id: ObjectId("YOUR_USER_ID") },
  {
    $set: {
      "integrations.zap": {
        encryptedApiKey: "YOUR_ENCRYPTED_API_KEY", // Use encryption utility
        storeId: null,
        companyName: null,
        isEnabled: true,
        lastSync: null,
        createdAt: new Date(),
        updatedAt: new Date()
      }
    }
  }
)
```

## Test the Integration

1. Start the server: `npm start`
2. Test API connection: `GET /api/zap/test`
3. Manual sync: `POST /api/zap/sync`
4. Check orders in WAITING_ACCEPTANCE: `GET /api/zap/waiting-orders`

## Notes

- The ZAP API URL is configured in `.env`: `ZAP_API_URL=https://zapgroupil-prod.mirakl.net`
- Automatic sync is controlled by: `ZAP_CRON_ENABLED=true/false`
- Cron schedule: `ZAP_CRON_SCHEDULE=*/2 * * * *` (every 2 minutes by default)
![1773060981610](image/DATABASE_SETUP/1773060981610.png)![1773061003813](image/DATABASE_SETUP/1773061003813.png)![1773061010691](image/DATABASE_SETUP/1773061010691.png)![1773061012724](image/DATABASE_SETUP/1773061012724.png)![1773061013672](image/DATABASE_SETUP/1773061013672.png)![1773061014289](image/DATABASE_SETUP/1773061014289.png)![1773061018891](image/DATABASE_SETUP/1773061018891.png)![1773061020368](image/DATABASE_SETUP/1773061020368.png)![1773061020957](image/DATABASE_SETUP/1773061020957.png)![1773061021557](image/DATABASE_SETUP/1773061021557.png)![1773061026571](image/DATABASE_SETUP/1773061026571.png)