Skip to content

Commit 1cd7465

Browse files
authored
Merge pull request #10 from gurumnyang/market
feat: sepearate student and business
2 parents 80e6385 + 819a407 commit 1cd7465

19 files changed

+873
-307
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.env
22
/node_modules/
33
/.idea/
4-
/cert/*
4+
/cert/*
5+
/tests/

models/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ mongoose.Promise = global.Promise;
44
const db = {};
55
db.mongoose = mongoose;
66
db.user = require("./user.model");
7+
db.market = require("./market.model");
8+
db.stamp = require("./stamp.model");
9+
db.stampPolicy = require("./stampRule");
710

811
module.exports = db;

models/market.model.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
const marketSchema = new Schema({
5+
name: {
6+
type: String,
7+
required: true,
8+
unique: true,
9+
minlength: 1,
10+
maxlength:20
11+
},
12+
address: {
13+
type: String,
14+
required: true
15+
},
16+
//@todo support soon
17+
coordinate: {
18+
latitude: {
19+
type: Number,
20+
},
21+
longitude: {
22+
type: Number,
23+
}
24+
},
25+
stampPolicies: [{
26+
type: Schema.Types.ObjectId,
27+
ref: 'stampPolicy'
28+
}],
29+
products: [{
30+
_id: {
31+
type: mongoose.Schema.Types.ObjectId,
32+
auto: true
33+
},
34+
name: {
35+
type: String,
36+
required: true,
37+
minlength: 1,
38+
maxlength: 20
39+
},
40+
price: {
41+
type: Number,
42+
required: true,
43+
min: 0
44+
}
45+
}],
46+
createdAt: {
47+
type: Date,
48+
default: Date.now
49+
},
50+
updatedAt: {
51+
type: Date,
52+
default: Date.now
53+
}
54+
});
55+
56+
module.exports = mongoose.model('market', marketSchema);

models/stamp.model.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
const stampSchema = new Schema({
5+
market: {
6+
type: Schema.Types.ObjectId,
7+
ref: 'market',
8+
},
9+
stampType: {
10+
type: Schema.Types.ObjectId,
11+
ref: 'stampPolicy',
12+
},
13+
user: {
14+
type: Schema.Types.ObjectId,
15+
ref: 'user',
16+
},
17+
count: {
18+
type: Number,
19+
required: true,
20+
min: 0,
21+
default: 0
22+
},
23+
createdAt: {
24+
type: Date,
25+
default: Date.now,
26+
},
27+
});
28+
29+
module.exports = mongoose.model('stamp', stampSchema);

models/stampRule.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
const stampRuleSchema = new Schema({
5+
market: {
6+
type: Schema.Types.ObjectId,
7+
ref: 'Market',
8+
required: true
9+
},
10+
name: {
11+
type: String,
12+
required: true,
13+
minlength: 1,
14+
maxlength: 20
15+
},
16+
requiredStamps: {
17+
type: Number,
18+
required: true,
19+
min: 1
20+
},
21+
reward: {
22+
type: String,
23+
required: true,
24+
minlength: 1,
25+
maxlength: 100
26+
},
27+
createdAt: {
28+
type: Date,
29+
default: Date.now
30+
},
31+
updatedAt: {
32+
type: Date,
33+
default: Date.now
34+
}
35+
});
36+
37+
module.exports = mongoose.model('stampRule', stampRuleSchema);

models/user.model.js

+37-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ const bcrypt = require('bcryptjs');
33
const Schema = mongoose.Schema;
44

55
const userSchema = new Schema({
6-
name: {
6+
//계정 활성화 여부
7+
//학생- 학교 계정 인증시 활성
8+
//점주- 인증키 입력시 활성
9+
isActive: {
10+
type: Boolean,
11+
default: false,
12+
},
13+
username: {
714
type: String,
815
required: true,
916
minlength: 1,
@@ -25,6 +32,35 @@ const userSchema = new Schema({
2532
enum: ['student', 'business','admin'],
2633
default: 'student',
2734
},
35+
business: {
36+
type: Schema.Types.ObjectId,
37+
ref: 'market',
38+
},
39+
//학생의 경우
40+
stamps: [{
41+
type: Schema.Types.ObjectId,
42+
ref: 'stamp',
43+
}],
44+
studentId: {
45+
type: String,
46+
minLength: 5,
47+
maxLength: 5
48+
},
49+
name: {
50+
type: String,
51+
minLength: 2,
52+
maxLength: 10,
53+
},
54+
//구글 계정 연동
55+
googleId: {
56+
type: String,
57+
unique: true,
58+
},
59+
email: {
60+
type: String,
61+
unique: true,
62+
},
63+
2864
createdAt: {
2965
type: Date,
3066
default: Date.now,

0 commit comments

Comments
 (0)