Initial commit: nick docs
This commit is contained in:
90
02 - Data Models/ShopSettings.md
Normal file
90
02 - Data Models/ShopSettings.md
Normal file
@@ -0,0 +1,90 @@
|
||||
---
|
||||
title: ShopSettings
|
||||
tags: [data-model, mongoose]
|
||||
aliases: [Shop, Storefront, IShopSettings]
|
||||
---
|
||||
|
||||
# ShopSettings
|
||||
|
||||
One-to-one storefront configuration for a seller. Holds the shop name, description, avatar, cover image, public visibility flag, review toggles (`allowSellerReviews`, `allowTemplateReviews`), and social links. The unique constraint on `sellerId` enforces the one-shop-per-seller invariant.
|
||||
|
||||
> [!note] Source
|
||||
> `backend/src/models/ShopSettings.ts:22` — schema definition
|
||||
> `backend/src/models/ShopSettings.ts:86` — model export
|
||||
|
||||
## Schema
|
||||
|
||||
| Field | Type | Required | Default | Validation | Index | Description |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `sellerId` | ObjectId → [[User]] | yes | — | — | unique | Owning seller (one shop per seller). |
|
||||
| `name` | String | yes | — | trim | — | Shop name. |
|
||||
| `description` | String | no | `""` | trim | — | Shop description. |
|
||||
| `avatar` | String | no | `""` | — | — | Avatar URL. |
|
||||
| `coverImage` | String | no | `""` | — | — | Cover image URL. |
|
||||
| `isPublic` | Boolean | no | `true` | — | — | Public visibility flag. |
|
||||
| `allowSellerReviews` | Boolean | no | `true` | — | — | Whether buyers can review the seller. |
|
||||
| `allowTemplateReviews` | Boolean | no | `true` | — | — | Whether buyers can review templates. |
|
||||
| `socialLinks.facebook` | String | no | `""` | — | — | Facebook URL. |
|
||||
| `socialLinks.instagram` | String | no | `""` | — | — | Instagram URL. |
|
||||
| `socialLinks.linkedin` | String | no | `""` | — | — | LinkedIn URL. |
|
||||
| `socialLinks.twitter` | String | no | `""` | — | — | Twitter / X URL. |
|
||||
| `createdAt` | Date | auto | — | — | — | Mongoose timestamp. |
|
||||
| `updatedAt` | Date | auto | — | — | — | Mongoose timestamp. |
|
||||
|
||||
## Virtuals
|
||||
|
||||
None defined.
|
||||
|
||||
## Indexes
|
||||
|
||||
- Implicit unique index on `sellerId` (from `unique: true`). No additional indexes are declared (see comment at `backend/src/models/ShopSettings.ts:84`).
|
||||
|
||||
## Pre/Post Hooks
|
||||
|
||||
None declared.
|
||||
|
||||
## Instance Methods
|
||||
|
||||
None defined.
|
||||
|
||||
## Static Methods
|
||||
|
||||
None defined.
|
||||
|
||||
## Relationships
|
||||
|
||||
- **References**: [[User]] (`sellerId`).
|
||||
- **Referenced by**: none. [[Review]] toggles for the seller are read from here.
|
||||
|
||||
## State Transitions
|
||||
|
||||
No status field. The `isPublic` boolean is the only visibility control:
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> public
|
||||
public --> private : seller toggles off
|
||||
private --> public : seller toggles on
|
||||
```
|
||||
|
||||
## Common Queries
|
||||
|
||||
```ts
|
||||
// Fetch the seller's shop
|
||||
ShopSettings.findOne({ sellerId });
|
||||
|
||||
// Upsert on first save
|
||||
ShopSettings.findOneAndUpdate(
|
||||
{ sellerId },
|
||||
{ $set: { name, description, ... } },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
|
||||
// Public shop directory
|
||||
ShopSettings.find({ isPublic: true }).sort({ createdAt: -1 });
|
||||
```
|
||||
|
||||
> [!warning] Creating two shops will fail
|
||||
> Inserting a second `ShopSettings` document with the same `sellerId` will fail with `E11000 duplicate key`. Application code should always use `findOneAndUpdate` with `upsert: true`.
|
||||
|
||||
Related: [[User]], [[Review]], [[RequestTemplate]].
|
||||
Reference in New Issue
Block a user