@positivegrid/pg-mongoose-schema 27.7.7 → 27.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ 'use strict'
2
+
3
+ module.exports = function (mongoose) {
4
+ const Schema = mongoose.Schema
5
+
6
+ const DataSourceSchema = new Schema({
7
+ type: {
8
+ type: String,
9
+ enum: ['tone_theme_query', 'tone_theme_ids'],
10
+ required: true
11
+ },
12
+ query: {
13
+ type: Schema.Types.Mixed,
14
+ default: null
15
+ },
16
+ ids: [{
17
+ type: String
18
+ }],
19
+ limit: {
20
+ type: Number,
21
+ default: 12
22
+ }
23
+ }, { _id: false })
24
+
25
+ const SectionSchema = new Schema({
26
+ section_type: {
27
+ type: String,
28
+ enum: ['banner', 'theme_list'],
29
+ required: true
30
+ },
31
+ title: {
32
+ type: String,
33
+ default: null
34
+ },
35
+ order: {
36
+ type: Number,
37
+ required: true
38
+ },
39
+ data_source: {
40
+ type: DataSourceSchema,
41
+ required: true
42
+ }
43
+ }, { _id: false })
44
+
45
+ const HomeConfigSchema = new Schema({
46
+ config_for: {
47
+ type: String,
48
+ required: true
49
+ },
50
+ locale: {
51
+ type: String,
52
+ default: 'en'
53
+ },
54
+ sections: [SectionSchema],
55
+ is_active: {
56
+ type: Boolean,
57
+ default: false
58
+ },
59
+ created_on: {
60
+ type: Date,
61
+ default: Date.now
62
+ },
63
+ updated_on: {
64
+ type: Date,
65
+ default: Date.now
66
+ }
67
+ }, {
68
+ collection: 'home_config'
69
+ })
70
+
71
+ // 索引
72
+ HomeConfigSchema.index({
73
+ config_for: 1,
74
+ locale: 1,
75
+ is_active: 1
76
+ })
77
+
78
+ mongoose.model('HomeConfig', HomeConfigSchema)
79
+ }
@@ -0,0 +1,78 @@
1
+ 'use strict'
2
+
3
+ const mongooseLeanVirtuals = require('mongoose-lean-virtuals')
4
+
5
+ module.exports = function (mongoose) {
6
+ const Schema = mongoose.Schema
7
+
8
+ const ToneThemeSchema = new Schema({
9
+ title: {
10
+ type: String,
11
+ required: true,
12
+ trim: true
13
+ },
14
+ description: {
15
+ type: String,
16
+ trim: true,
17
+ default: null
18
+ },
19
+ cover_image_url: {
20
+ type: String,
21
+ default: null
22
+ },
23
+ thumb_url: {
24
+ type: String,
25
+ default: null
26
+ },
27
+ order: {
28
+ type: Number,
29
+ default: 0
30
+ },
31
+ is_shown: {
32
+ type: Boolean,
33
+ default: false
34
+ },
35
+ list_for: {
36
+ type: String,
37
+ required: true
38
+ },
39
+ category: {
40
+ type: String,
41
+ default: null
42
+ },
43
+ tags: [{
44
+ type: String
45
+ }],
46
+ created_on: {
47
+ type: Date,
48
+ default: Date.now
49
+ },
50
+ updated_on: {
51
+ type: Date,
52
+ default: Date.now
53
+ }
54
+ }, {
55
+ collection: 'tone_theme',
56
+ toJSON: { virtuals: true },
57
+ toObject: { virtuals: true }
58
+ })
59
+
60
+ // 索引
61
+ ToneThemeSchema.index({
62
+ list_for: 1,
63
+ is_shown: 1,
64
+ order: 1,
65
+ created_on: -1
66
+ })
67
+ ToneThemeSchema.index({ category: 1 })
68
+ ToneThemeSchema.index({ tags: 1 })
69
+
70
+ ToneThemeSchema.plugin(mongooseLeanVirtuals)
71
+
72
+ ToneThemeSchema.virtual('id')
73
+ .get(function () {
74
+ return this._id.toHexString()
75
+ })
76
+
77
+ mongoose.model('ToneTheme', ToneThemeSchema)
78
+ }
@@ -0,0 +1,49 @@
1
+ 'use strict'
2
+
3
+ module.exports = function (mongoose) {
4
+ const Schema = mongoose.Schema
5
+ const ObjectId = Schema.Types.ObjectId
6
+
7
+ const ToneThemeFeaturedListSchema = new Schema({
8
+ tone_theme_id: {
9
+ type: ObjectId,
10
+ ref: 'ToneTheme',
11
+ required: true
12
+ },
13
+ featured_list_id: {
14
+ type: ObjectId,
15
+ ref: 'FeaturedList',
16
+ required: true
17
+ },
18
+ order: {
19
+ type: Number,
20
+ default: 0
21
+ },
22
+ created_on: {
23
+ type: Date,
24
+ default: Date.now
25
+ }
26
+ }, {
27
+ collection: 'tone_theme_featured_list'
28
+ })
29
+
30
+ // 索引
31
+ ToneThemeFeaturedListSchema.index({
32
+ tone_theme_id: 1,
33
+ order: 1
34
+ })
35
+
36
+ ToneThemeFeaturedListSchema.index({
37
+ featured_list_id: 1
38
+ })
39
+
40
+ // 確保同一個 featured_list 不會被加入同一個 theme 兩次
41
+ ToneThemeFeaturedListSchema.index({
42
+ tone_theme_id: 1,
43
+ featured_list_id: 1
44
+ }, {
45
+ unique: true
46
+ })
47
+
48
+ mongoose.model('ToneThemeFeaturedList', ToneThemeFeaturedListSchema)
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@positivegrid/pg-mongoose-schema",
3
- "version": "27.7.7",
3
+ "version": "27.8.1",
4
4
  "description": "Positive Grid mongoose schema",
5
5
  "author": "Ferrari Lee <shiyung@positivegrid.com>",
6
6
  "homepage": "https://git.positivegrid.com:8443/backend/pg-mongoose-schema",