-
Notifications
You must be signed in to change notification settings - Fork 0
/
snippets.js
140 lines (108 loc) · 3.16 KB
/
snippets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//getTime
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
var hour = today.getHours()+1;//Hours are from 0 to 23!
var minutes = today.getMinutes();
var ampm;
function getTime(){
var date;
if(mm<10) {
mm='0'+mm
}
if(hour>12){
hour=2%hour
ampm='pm'
}
else{
ampm ='am'
}
date = mm+'/'+dd+'/'+yyyy+' '+hour+' :'+minutes+' '+ampm;
return date;
}
//angular controller
app.controller('ControllerNames(plural-capital naming convention)', ['$scope', 'someFactory', '$routeParams', '$localStorage', '$location', function($scope, someFactory, $routeParams, $localStorage, $location){
}])
//angular controller function
$scope.variable = function(){
console.log(' controller function fired')
}
//angular factory
app.factory('defaultFactory (camel case singular)', ['$http', function($http){
console.log(" factory loaded!");
var factory={};
return factory
}])
//angular factory function
factory.function = function(passin, callback){
console.log(' factory function fired')
}
//get
$http.get('/route').then(callback)
//post
$http.post('/route', passin).then(callback)
//console.log
console.log()
//mean child
_association_children:[{type: Schema.Types.ObjectId, ref: 'name_of_foreighn_model'}]//one to many where this is the many
//mean function
this.function = function(req,res){
console.log(' server controller function fired')
}
//mean parent
_association_parent: {type: Schema.Types.ObjectId, ref: 'name_of_foreighn_model'},//one to many where this is the one
//mean model
console.log(' server model');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var GenericSchema = new mongoose.Schema({
}, {timestamps: true });
var name_of_model = mongoose.model('name_of_model', GenericSchema);
//mean validate
{
validate:{ //make this an array of objects for multiple validation objects
validator: function( value ){
//validation function goes here
},
message:'failure message goes here'
}
},
//mean populate
this.populate = function(req,res){
Model.find({_id: req.params.id }).populate('name of field you want to populate').exec(function(err, results){
if(err){
console.log(err)
return
res.json(results)
}
})
}
//mean search
this.search = function(req,res){
Model.find({text:{$regex:req.body.text /* (returns results containing the entered string) */, : 'i'}}).exec(function (err, results){
if(err){
console.log('no matches')
return
res.json(results)
}
})
}
//mean controller
console.log(' server controller');
var mongoose = require('mongoose');
var name_of_model = mongoose.model('name_of_model');
function PluralNamingConventionPascalCase(){
}
module.exports = new PluralNamingConventionPascalCase();
//Other useful code
// angular sort by creation newest to olderst<ng-repeat='' | orderBy:'created_at':true>
this.orderByDate = function(req,res){
Model.find({}).sort('date'/* use -date for oldest to newest */).exec(function(err, results){
if(err){
console.log(err)
return
}
res.json(results)
})
}