Skip to content

Commit

Permalink
needs reword / undo
Browse files Browse the repository at this point in the history
  • Loading branch information
mkevenaar committed May 4, 2022
1 parent 645547f commit 3603b02
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/database/models/reason.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import mongoose from 'mongoose';

const ReasonSchema = new mongoose.Schema({
reason: { type: String },
registeredAt: { type: Number, default: Date.now }, // `Date.now()` returns the current unix timestamp as a number
});

export const ReasonModel = mongoose.model('reason', ReasonSchema);
9 changes: 8 additions & 1 deletion src/database/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import mongoose from 'mongoose';

const UserSchema = new mongoose.Schema({
id: { type: String },
registeredAt: { type: Number, default: Date.now() },
guild: { type: String },
registeredAt: { type: Number, default: Date.now }, // `Date.now()` returns the current unix timestamp as a number
reputation: { type: Number, default: 0 },
reason: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "reason"
}
],
});

export const UserModel = mongoose.model('user', UserSchema);
5 changes: 3 additions & 2 deletions src/database/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ export class UserService {
/**
* Get or Create a User entry based on its ID
*/
static async fetchUser(key) {
let userEntry = await UserModel.findOne({ id: key });
static async fetchUser(key, guildId) {
let userEntry = await UserModel.findOne({ id: key, guild: guildId });
if (userEntry) {
return userEntry;
}

userEntry = new UserModel({
id: key,
guild: guildId,
registeredAt: Date.now(),
});
await userEntry.save().catch((err) => console.log(err));
Expand Down

0 comments on commit 3603b02

Please sign in to comment.