This repository was archived by the owner on Sep 8, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 11var module = angular . module ( 'App.User' ) ;
22module . factory ( 'User' , ( BaseObject , $http ) => {
33 class User extends BaseObject {
4+ /**
5+ * Get list of users
6+ *
7+ * @returns {Promise<User[]> }
8+ */
49 static list ( ) {
510 return $http . get ( '/api/users' )
6- . then ( ( response ) => response . data . map ( User . new ) ) ;
11+ . then ( ( response ) => response . data . map ( user => new User ( user ) ) ) ;
712 }
813
914
10- // checks validity of the property (probably should be in BaseObject)
15+ /**
16+ * Validity function for use in the view / form
17+ *
18+ * @note Client-side validation is a convenience, server-side validation is imperative
19+ */
1120 validate ( property ) {
1221 if ( ! User . rules [ property ] )
1322 return true ;
1423
1524 var pattern = new RegExp ( User . rules [ property ] ) ;
1625 return pattern . test ( this [ property ] ) ;
1726 }
27+
28+ create ( ) {
29+ return this . cache ( 'creating' , ( ) =>
30+ $http . post ( '/api/users' , this )
31+ // Attach additional data from server to this object
32+ . then ( data => Object . assign ( this , data ) )
33+ ) ;
34+ }
35+
36+ update ( ) {
37+ return this . cache ( 'updating' , ( ) =>
38+ $http . put ( '/api/users' , this )
39+ // Attach additional data from server to this object
40+ . then ( data => Object . assign ( this , data ) )
41+ ) ;
42+ }
1843 }
1944
2045 User . rules = {
You can’t perform that action at this time.
0 commit comments