1
- const mongoose = require ( 'mongoose' ) ;
1
+ // const mongoose = require('mongoose');
2
+ // const User = require('../../user-service/model/user-model');
3
+ // const Question = require('../../user-service/model/Questions');
2
4
3
- const HistorySchema = new mongoose . Schema ( {
5
+
6
+ // mongoose.model('User', User.schema);
7
+ // mongoose.model('Question', Question.schema);
8
+
9
+
10
+ // const HistorySchema = new mongoose.Schema({
11
+ // user: {
12
+ // type: mongoose.Schema.Types.ObjectId,
13
+ // ref: 'User',
14
+ // required: true // The user for whom this history entry is being created
15
+ // },
16
+ // matchedUser: {
17
+ // type: mongoose.Schema.Types.ObjectId,
18
+ // ref: 'User',
19
+ // required: true // The other user they were matched with
20
+ // },
21
+ // question: {
22
+ // type: mongoose.Schema.Types.ObjectId, // Reference to the Question model
23
+ // ref: 'Question',
24
+ // required: true
25
+ // },
26
+ // datetime: {
27
+ // type: Date, // Time when the session started
28
+ // default: Date.now
29
+ // },
30
+ // duration: {
31
+ // type: Number, // Duration in minutes for the individual user
32
+ // required: true
33
+ // },
34
+ // code: {
35
+ // type: Number, // Store the code as binary file
36
+ // required: true
37
+ // }
38
+ // });
39
+
40
+ // // HistorySchema.virtual('matchedUserName').get(function() {
41
+ // // return this.matchedUser.username;
42
+ // // });
43
+
44
+ // // HistorySchema.virtual('questionTitle').get(function() {
45
+ // // return this.question.title;
46
+ // // });
47
+
48
+ // // Create the History model
49
+ // const HistoryModel = mongoose.model('History', HistorySchema, 'Histories');
50
+ // module.exports = HistoryModel;
51
+
52
+
53
+ const mongoose = require ( "mongoose" ) ;
54
+ const Schema = mongoose . Schema ;
55
+
56
+ async function getUserModel ( ) {
57
+ return await import ( '../../user-service/model/user-model' ) ;
58
+ }
59
+
60
+ async function init ( ) {
61
+ // const User = await import('../../user-service/model/user-model');
62
+ const UserModel = await getUserModel ( ) ;
63
+ const Question = await import ( '../../user-service/model/Questions' ) ;
64
+
65
+ mongoose . model ( 'User' , User . default . schema ) ;
66
+ mongoose . model ( 'Question' , Question . default . schema ) ;
67
+
68
+
69
+ const HistorySchema = new mongoose . Schema ( {
4
70
user : {
5
71
type : mongoose . Schema . Types . ObjectId ,
6
72
ref : 'User' ,
@@ -25,11 +91,14 @@ const HistorySchema = new mongoose.Schema({
25
91
required : true
26
92
} ,
27
93
code : {
28
- type : Buffer , // Store the code as binary file
94
+ type : Number , // Store the code as binary file
29
95
required : true
30
96
}
31
97
} ) ;
32
98
33
- // Create the History model
34
- const HistoryModel = mongoose . model ( 'History' , HistorySchema , 'History' ) ;
35
- module . exports = HistoryModel ;
99
+ const HistoryModel = mongoose . model ( 'History' , HistorySchema ) ;
100
+
101
+ module . exports = HistoryModel ;
102
+ }
103
+
104
+ init ( ) . catch ( console . error ) ;
0 commit comments