mirror of
https://github.com/yusufipk/RememberMe.git
synced 2026-09-11 10:56:07 +00:00
changed some lines to be compaitable with rememberme-cli
This commit is contained in:
@@ -55,7 +55,7 @@ Here are the example requests you can make.
|
|||||||
{
|
{
|
||||||
"name": "Mike",
|
"name": "Mike",
|
||||||
"metAt": "Wall Maria Cafe",
|
"metAt": "Wall Maria Cafe",
|
||||||
"place": "Üsküdar"
|
"place": "Üsküdar",
|
||||||
"contact": {
|
"contact": {
|
||||||
"phone": "12345",
|
"phone": "12345",
|
||||||
"email": "[email protected]",
|
"email": "[email protected]",
|
||||||
|
|||||||
+43
-61
@@ -4,68 +4,55 @@ const Joi = require("joi");
|
|||||||
const personSchema = new mongoose.Schema({
|
const personSchema = new mongoose.Schema({
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 3,
|
|
||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
trim: true,
|
trim: true,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
metAt: {
|
metAt: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 3,
|
|
||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
place: {
|
place: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 3,
|
|
||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
},
|
},
|
||||||
contact: {
|
contact: {
|
||||||
type: new mongoose.Schema({
|
phone: {
|
||||||
phone: {
|
type: String,
|
||||||
|
maxlength: 20,
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 255,
|
||||||
|
},
|
||||||
|
socialmedia: {
|
||||||
|
instagram: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 5,
|
maxlength: 15,
|
||||||
maxlength: 20,
|
unqiue: true,
|
||||||
},
|
},
|
||||||
email: {
|
youtube: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 5,
|
maxlength: 15,
|
||||||
maxlength: 255,
|
|
||||||
},
|
},
|
||||||
socialmedia: {
|
twitter: {
|
||||||
type: new mongoose.Schema({
|
|
||||||
instagram: {
|
|
||||||
type: String,
|
|
||||||
minlength: 3,
|
|
||||||
maxlength: 15,
|
|
||||||
unqiue: true,
|
|
||||||
},
|
|
||||||
youtube: {
|
|
||||||
type: String,
|
|
||||||
minlength: 3,
|
|
||||||
maxlength: 15,
|
|
||||||
},
|
|
||||||
twitter: {
|
|
||||||
type: String,
|
|
||||||
minlength: 3,
|
|
||||||
maxlength: 15,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
website: {
|
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 5,
|
maxlength: 15,
|
||||||
maxlength: 25,
|
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
|
website: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 25,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
birth: {
|
birth: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 25,
|
maxlength: 25,
|
||||||
},
|
},
|
||||||
age: {
|
age: {
|
||||||
type: Number,
|
type: String,
|
||||||
maxlength: 100,
|
maxlength: 2,
|
||||||
},
|
},
|
||||||
likes: {
|
likes: {
|
||||||
type: [String],
|
type: [String],
|
||||||
@@ -75,22 +62,18 @@ const personSchema = new mongoose.Schema({
|
|||||||
},
|
},
|
||||||
occupation: {
|
occupation: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 3,
|
|
||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
},
|
},
|
||||||
lastseen: {
|
lastseen: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 3,
|
|
||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
},
|
},
|
||||||
nextcontact: {
|
nextcontact: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 3,
|
|
||||||
maxlength: 50,
|
maxlength: 50,
|
||||||
},
|
},
|
||||||
notes: {
|
notes: {
|
||||||
type: String,
|
type: String,
|
||||||
minlength: 3,
|
|
||||||
maxlength: 500,
|
maxlength: 500,
|
||||||
},
|
},
|
||||||
tags: {
|
tags: {
|
||||||
@@ -105,8 +88,7 @@ const personSchema = new mongoose.Schema({
|
|||||||
},
|
},
|
||||||
createdAt: {
|
createdAt: {
|
||||||
type: String,
|
type: String,
|
||||||
maxlength: 25,
|
maxlength: 30,
|
||||||
required: true,
|
|
||||||
},
|
},
|
||||||
editedAt: {
|
editedAt: {
|
||||||
type: Date,
|
type: Date,
|
||||||
@@ -119,29 +101,29 @@ const Person = mongoose.model("Person", personSchema);
|
|||||||
|
|
||||||
function validatePerson(value) {
|
function validatePerson(value) {
|
||||||
const schema = Joi.object({
|
const schema = Joi.object({
|
||||||
name: Joi.string().min(3).max(50).required(),
|
name: Joi.string().max(50).required(),
|
||||||
metAt: Joi.string().min(3).max(50).required(),
|
metAt: Joi.string().max(50).required(),
|
||||||
place: Joi.string().min(3).max(50),
|
place: Joi.string().allow("").max(50),
|
||||||
contact: Joi.object({
|
contact: Joi.object({
|
||||||
phone: Joi.string().min(5).max(20),
|
phone: Joi.string().allow("").max(20),
|
||||||
email: Joi.string().email().min(5).max(255),
|
email: Joi.string().allow("").email().max(255),
|
||||||
socialmedia: Joi.object({
|
socialmedia: Joi.object({
|
||||||
instagram: Joi.string().min(3).max(15),
|
instagram: Joi.string().allow("").max(15),
|
||||||
youtube: Joi.string().min(3).max(15),
|
youtube: Joi.string().allow("").max(15),
|
||||||
twitter: Joi.string().min(3).max(15),
|
twitter: Joi.string().allow("").max(15),
|
||||||
}),
|
}),
|
||||||
website: Joi.string().min(5).max(25),
|
website: Joi.string().allow("").max(25),
|
||||||
}),
|
}),
|
||||||
birth: Joi.string().max(25),
|
birth: Joi.string().allow("").max(25),
|
||||||
age: Joi.number().max(100),
|
age: Joi.string().allow("").max(100),
|
||||||
likes: Joi.array(),
|
likes: Joi.array().allow(""),
|
||||||
dislikes: Joi.array(),
|
dislikes: Joi.array().allow(""),
|
||||||
occupation: Joi.string().min(3).max(50),
|
occupation: Joi.string().allow("").max(50),
|
||||||
lastseen: Joi.string().min(3).max(50),
|
lastseen: Joi.string().allow("").max(50),
|
||||||
nextcontact: Joi.string().min(3).max(50),
|
nextcontact: Joi.string().allow("").max(50),
|
||||||
notes: Joi.string().min(3).max(500),
|
notes: Joi.string().allow("").max(500),
|
||||||
tags: Joi.array().max(6),
|
tags: Joi.array().allow("").max(6),
|
||||||
createdAt: Joi.string().max(25).required(),
|
createdAt: Joi.string().allow("").max(30),
|
||||||
});
|
});
|
||||||
return schema.validate(value, { allowUnknown: true });
|
return schema.validate(value, { allowUnknown: true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
"supertest": "^6.1.4"
|
"supertest": "^6.1.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
|
"devStart": "nodemon index.js",
|
||||||
"test": "jest --watchAll --verbose --runInBand --coverage"
|
"test": "jest --watchAll --verbose --runInBand --coverage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-2
@@ -5,7 +5,7 @@ const express = require("express");
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.get("/", auth, async (req, res) => {
|
router.get("/", auth, async (req, res) => {
|
||||||
const people = await Person.find();
|
const people = await Person.find().sort("field name");
|
||||||
res.send(people);
|
res.send(people);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -77,6 +77,7 @@ router.put("/:id", auth, validateObjectId, async (req, res) => {
|
|||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
place,
|
place,
|
||||||
|
metAt,
|
||||||
contact,
|
contact,
|
||||||
birth,
|
birth,
|
||||||
age,
|
age,
|
||||||
@@ -87,11 +88,22 @@ router.put("/:id", auth, validateObjectId, async (req, res) => {
|
|||||||
nextcontact,
|
nextcontact,
|
||||||
notes,
|
notes,
|
||||||
tags,
|
tags,
|
||||||
|
createdAt,
|
||||||
} = person;
|
} = person;
|
||||||
|
|
||||||
if (!req.body.name) req.body.name = name;
|
if (!req.body.name) req.body.name = name;
|
||||||
|
if (!req.body.metAt) req.body.metAt = metAt;
|
||||||
if (!req.body.place) req.body.place = place;
|
if (!req.body.place) req.body.place = place;
|
||||||
if (!req.body.contact) req.body.contact = contact;
|
|
||||||
|
if (!req.body.contact.socialmedia.instagram)
|
||||||
|
req.body.contact.socialmedia.instagram = contact.socialmedia.instagram;
|
||||||
|
if (!req.body.contact.socialmedia.youtube)
|
||||||
|
req.body.contact.socialmedia.youtube = contact.socialmedia.youtube;
|
||||||
|
if (!req.body.contact.socialmedia.twitter)
|
||||||
|
req.body.contact.socialmedia.twitter = contact.socialmedia.twitter;
|
||||||
|
if (!req.body.contact.phone) req.body.contact.phone = contact.phone;
|
||||||
|
if (!req.body.contact.email) req.body.contact.email = contact.email;
|
||||||
|
|
||||||
if (!req.body.birth) req.body.birth = birth;
|
if (!req.body.birth) req.body.birth = birth;
|
||||||
if (!req.body.age) req.body.age = age;
|
if (!req.body.age) req.body.age = age;
|
||||||
if (!req.body.likes) req.body.likes = likes;
|
if (!req.body.likes) req.body.likes = likes;
|
||||||
@@ -101,6 +113,7 @@ router.put("/:id", auth, validateObjectId, async (req, res) => {
|
|||||||
if (!req.body.nextcontact) req.body.nextcontact = nextcontact;
|
if (!req.body.nextcontact) req.body.nextcontact = nextcontact;
|
||||||
if (!req.body.notes) req.body.notes = notes;
|
if (!req.body.notes) req.body.notes = notes;
|
||||||
if (!req.body.tags) req.body.tags = tags;
|
if (!req.body.tags) req.body.tags = tags;
|
||||||
|
if (!req.body.createdAt) req.body.createdAt = createdAt;
|
||||||
|
|
||||||
const { error } = validate(req.body);
|
const { error } = validate(req.body);
|
||||||
if (error) return res.status(400).send(error.details[0].message);
|
if (error) return res.status(400).send(error.details[0].message);
|
||||||
|
|||||||
@@ -199,6 +199,18 @@ describe("person route", () => {
|
|||||||
person2 = {
|
person2 = {
|
||||||
name: "Jimmy",
|
name: "Jimmy",
|
||||||
metAt: "Texas",
|
metAt: "Texas",
|
||||||
|
|
||||||
|
// created contact empty because I want tests to work with rememberme-cli
|
||||||
|
contact: {
|
||||||
|
socialmedia: {
|
||||||
|
instagram: "",
|
||||||
|
youtube: "",
|
||||||
|
twitter: "",
|
||||||
|
},
|
||||||
|
phone: "",
|
||||||
|
email: "",
|
||||||
|
},
|
||||||
|
|
||||||
createdAt: "11.11.2021",
|
createdAt: "11.11.2021",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user