Welcome back to Daily Two Cents!

Today was a busy day for me, meaning I didn't have as much time to focus on code. That being said I did manage to write out the models that I'm going to use for my bujo application. It was easy because while I was working on my frontend I used json server which is a fake REST api that you can set up pretty easily. This allowed me to write out all of my frontend code, including redux, allowing me to make sure it works without going all in on a backend server.

Moving over the "models" from the fake API to the actually js model files was pretty easy since I had everything I needed to make a mongoose model. I'll be going over the model for each of my collections today so lets get started.

const mongoose = require('mongoose');
const uuidv4 = require('uuid').v4();

const UserSchema = mongoose.Schema({
  _id: {
    type: String,
    default: uuidv4,
    required: true,
  },
  email: {
    type: String,
    required: true,
  },
  password: {
    type: String,
    required: true,
  },
  reset_token: {
    type: String,
    required: false,
  },
  reset_expires: {
    type: Date,
    required: false,
  },
});

module.exports = mongoose.model('users', UserSchema);

So this is the model for my User collection. At the top I require mongoose, for obvious reasons, and uuidv4. I'm using the uuid package so I can automatically generate uuids for the data I will be adding to the database.

Now for the columns. since this is for a user, I included both the email and password and had them required. Of course the password will be hashed, but I haven't gotten there yet. For the resettoken and resetexpires columns, I plan on adding a reset password functionality to my site so I'll add them ahead of time. They are also not required because you're not going to need a token to reset your password all the time. Then at the final line we export the schema using the mongoose.model function.

Now for the bullets model.

const mongoose = require('mongoose');
const uuidv4 = require('uuid').v4();

const BulletSchema = mongoose.Schema({
  _id: {
    type: String,
    default: uuidv4,
    required: true,
  },
  name: {
    type: String,
    required: true,
  },
  type: {
    type: String,
    required: true,
  },
  date: {
    type: Date,
    default: Date.now(),
    required: true,
  },
  priority: {
    type: Boolean,
    required: true,
  },
  userId: {
    type: String,
    required: true,
  },
});

module.exports = mongoose.model('bullets', BulletSchema);

I'll focus more on the columns for this one since the top 2 lines and final lines are more or less the same.

The name column is for the name of the "bullet," while the type is for what kind of bullet it is (task, event, or note). The date is when the bullet was created, so I can sort by the date. You can also notice I have a default value of Daet.now() to help me with that. Now priority is a boolean because you're either going to want to really focus on completing a bullet or not. And the useId column is so I can know which bullet belongs to which user.

Bit of a lengthy explanation for today for not a lot done, but I'm still proud of my progress. I'm going to sign off here, and I'll see you guys tomorrow. Peace!

This post is also available on DEV.