Skip to content

Commit

Permalink
Code: Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ppg committed Apr 20, 2020
1 parent ceecb27 commit bf3ee8e
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fastify.register(
settings: {
useNewUrlParser: true,
config: {
autoIndex: true
}
autoIndex: true,
},
},
models: [
{
Expand All @@ -31,56 +31,61 @@ fastify.register(
schema: {
title: {
type: String,
required: true
required: true,
},
content: {
type: String,
required: true
}
}
required: true,
},
// We can add references to other Schemas like-so
author: {
type: "ObjectId",
ref: "Account",
validateExistance: true,
},
},
},
{
name: "accounts",
alias: "Account",
schema: {
username: {
type: String
type: String,
},
password: {
type: String,
select: false,
required: true
required: true,
},
email: {
type: String,
unique: true,
required: true,
validate: {
validator: v => {
validator: (v) => {
// Super simple email regex: https://stackoverflow.com/a/4964763/7028187
return /^.+@.{2,}\..{2,}$/.test(v);
},
message: props => `${props.value} is not a valid email!`
}
message: (props) => `${props.value} is not a valid email!`,
},
},
// We can add references to other Schemas like-so
posts: [
{
type: "ObjectId",
ref: "Post",
validateExistance: true
}
],
createdAtUTC: {
type: Date,
required: true
}
}
}
required: true,
},
},
virtualize: (schema) => {
schema.virtual("posts", {
ref: "Post",
localKey: "_id",
foreignKey: "author",
});
},
},
],
useNameAndAlias: true
useNameAndAlias: true,
},
err => {
(err) => {
if (err) throw err;
}
);
Expand Down

0 comments on commit bf3ee8e

Please sign in to comment.