Skip to content

Commit

Permalink
Removing undefined defaults from model. The reason they were there in…
Browse files Browse the repository at this point in the history
… the first place was because of the way the changeAwareDecorator worked. If the entity did not exist and the property was not defined to something, changeAware would not register changes to those properties. ChangeAware implementation has changed now.
  • Loading branch information
Jeremy Sik committed Dec 23, 2015
1 parent b9cf2c6 commit 5628bf7
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 88 deletions.
20 changes: 8 additions & 12 deletions app/src/common/models/abstractModel.spec.ts
Expand Up @@ -15,12 +15,12 @@ namespace common.models {
bar: sinon.stub().returns('bar')
};

public foo:string = undefined;
public bar:string = undefined;
public foobar:string = undefined;
public foo:string;
public bar:string;
public foobar:string;
public _hasOne:TestChildModel;
public _hasMany:TestChildModel[];
public _hydrate:TestChildModel[];
public _hasMany:TestChildModel[] = [];
public _hydrate:TestChildModel[] = [];

private hydrateFunction(data:any, exists:boolean) {
if(exists) {
Expand Down Expand Up @@ -95,9 +95,7 @@ namespace common.models {
}, false);

expect(model.getAttributes()).to.deep.equal({
foo: 'bar',
bar: undefined,
foobar: undefined
foo: 'bar'
});

});
Expand All @@ -111,11 +109,9 @@ namespace common.models {

expect(model.getAttributes(true)).to.deep.equal({
foo: 'bar',
bar: undefined,
foobar: undefined,
_hydrate : ['foobar'],
_hasOne: null,
_hasMany: null,
_hasOne : undefined,
_hasMany: [],
});

});
Expand Down
2 changes: 1 addition & 1 deletion app/src/common/models/abstractModel.ts
Expand Up @@ -160,7 +160,7 @@ namespace common.models {

_.forIn(this.__nestedEntityMap, (nestedObject:IModelClass|IHydrateFunction, nestedKey:string) => {

let nestedData = null;
let nestedData = this[nestedKey]; // Default to what the default model is defined in the model

if(this.isModelClass(nestedObject)) {
if(_.has(data, nestedKey) && !_.isNull(data[nestedKey])) {
Expand Down
8 changes: 4 additions & 4 deletions app/src/common/models/article/articleCommentModel.ts
Expand Up @@ -12,10 +12,10 @@ namespace common.models {
updatedAt: this.castMoment,
};

public articleCommentId:string = undefined;
public body:string = undefined;
public createdAt:moment.Moment = undefined;
public _author:common.models.User = undefined;
public articleCommentId:string;
public body:string;
public createdAt:moment.Moment;
public _author:common.models.User;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down
30 changes: 15 additions & 15 deletions app/src/common/models/article/articleModel.ts
Expand Up @@ -22,27 +22,27 @@ namespace common.models {

protected __primaryKey:string = 'postId';

public postId:string = undefined;
public title:string = undefined;
public shortTitle:string = undefined;
public permalink:string = undefined;
public content:string = undefined;
public status:string = undefined;
public authorId:string = undefined;
public thumbnailImageId:string = undefined;
public postId:string;
public title:string;
public shortTitle:string;
public permalink:string;
public content:string;
public status:string;
public authorId:string;
public thumbnailImageId:string;

public authorOverride:string = undefined;
public showAuthorPromo:boolean = undefined;
public authorWebsite:string = undefined;
public authorOverride:string;
public showAuthorPromo:boolean;
public authorWebsite:string;

public publicAccess:boolean = undefined;
public usersCanComment:boolean = undefined;
public publicAccess:boolean;
public usersCanComment:boolean;

public sectionsDisplay:mixins.ISectionsDisplay = undefined;
public sectionsDisplay:mixins.ISectionsDisplay;

public _sections:Section<any>[] = [];
public _metas:Meta[] = [];
public _author:User = undefined;
public _author:User;
public _tags:LinkingTag[] = [];
public _comments:ArticleComment[] = [];
public _localizations:Localization<Article>[] = [];
Expand Down
12 changes: 6 additions & 6 deletions app/src/common/models/image/imageModel.ts
Expand Up @@ -3,12 +3,12 @@ namespace common.models {
@common.decorators.changeAware
export class Image extends AbstractModel{

public imageId:string = undefined;
public version:number = undefined;
public folder:string = undefined;
public format:string = undefined;
public alt:string = undefined;
public title:string = undefined;
public imageId:string;
public version:number;
public folder:string;
public format:string;
public alt:string;
public title:string;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down
10 changes: 5 additions & 5 deletions app/src/common/models/meta/metaModel.ts
Expand Up @@ -3,11 +3,11 @@ namespace common.models {
@common.decorators.changeAware
export class Meta extends AbstractModel {

public metaId:string = undefined;
public metaableId:string = undefined;
public metaableType:string = undefined;
public metaName:string = undefined;
public metaContent:string = undefined;
public metaId:string;
public metaableId:string;
public metaableType:string;
public metaName:string;
public metaContent:string;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down
4 changes: 2 additions & 2 deletions app/src/common/models/section/sectionModel.ts
Expand Up @@ -23,8 +23,8 @@ namespace common.models {
public sectionId:string;
public content:T;
public type:string;
public createdAt:moment.Moment = undefined;
public updatedAt:moment.Moment = undefined;
public createdAt:moment.Moment;
public updatedAt:moment.Moment;

public _localizations:Localization<Section<T>>[] = [];

Expand Down
4 changes: 2 additions & 2 deletions app/src/common/models/section/sections/blockquoteModel.ts
Expand Up @@ -4,8 +4,8 @@ namespace common.models.sections {

public static contentType = 'blockquote';

public body:string = undefined;
public author:string = undefined;
public body:string;
public author:string;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down
4 changes: 2 additions & 2 deletions app/src/common/models/section/sections/mediaModel.ts
Expand Up @@ -87,8 +87,8 @@ namespace common.models.sections {
public static mediaTypes:string[] = [Media.mediaTypeImage, Media.mediaTypeVideo];

public media:(IImageContent|IVideoContent)[] = [];
public size:string = undefined;
public alignment:string = undefined;
public size:string;
public alignment:string;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down
2 changes: 1 addition & 1 deletion app/src/common/models/section/sections/richTextModel.ts
Expand Up @@ -3,7 +3,7 @@ namespace common.models.sections {
export class RichText extends AbstractModel {
public static contentType = 'rich_text';

public body:string = undefined;
public body:string;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down
10 changes: 5 additions & 5 deletions app/src/common/models/tag/tagModel.ts
Expand Up @@ -22,11 +22,11 @@ namespace common.models {
_childTags: CategoryTag,
};

public tagId:string = undefined;
public tag:string = undefined;
public searchable:boolean = undefined;
public tagId:string;
public tag:string;
public searchable:boolean;

public _childTags:CategoryTag[] = undefined;
public _childTags:CategoryTag[] = [];

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand All @@ -37,7 +37,7 @@ namespace common.models {

export abstract class PivotableTag<PivotType> extends Tag {

public _pivot:PivotType = undefined;
public _pivot:PivotType;

}

Expand Down
6 changes: 3 additions & 3 deletions app/src/common/models/user/userCredentialModel.ts
Expand Up @@ -3,9 +3,9 @@ module common.models {
@common.decorators.changeAware
export class UserCredential extends AbstractModel implements global.IUserCredential{

public userId:string = undefined;
public userCredentialId:string = undefined;
public password:string = undefined;
public userId:string;
public userCredentialId:string;
public password:string;

constructor(data:any, exists:boolean = false) {

Expand Down
32 changes: 16 additions & 16 deletions app/src/common/models/user/userModel.ts
Expand Up @@ -17,23 +17,23 @@ namespace common.models {

protected __primaryKey = 'userId';

public userId:string = undefined;
public email:string = undefined;
public username:string = undefined;
public firstName:string = undefined;
public lastName:string = undefined;
public emailConfirmed:string = undefined;
public country:string = undefined;
public regionCode:string = undefined;
public avatarImgUrl:string = undefined;
public avatarImgId:string = undefined;
public timezoneIdentifier:string = undefined;
public _userCredential:UserCredential = undefined;
public _userProfile:common.models.UserProfile = undefined;
public _socialLogins:common.models.UserSocialLogin[] = undefined;
public _roles:common.models.RoleAssignment[] = undefined;
public userId:string;
public email:string;
public username:string;
public firstName:string;
public lastName:string;
public emailConfirmed:string;
public country:string;
public regionCode:string;
public avatarImgUrl:string;
public avatarImgId:string;
public timezoneIdentifier:string;
public _userCredential:UserCredential;
public _userProfile:common.models.UserProfile;
public _socialLogins:common.models.UserSocialLogin[] = [];
public _roles:common.models.RoleAssignment[] = [];
public roles:string[] = []; //list of role keys, supplied in token
public _uploadedAvatar:common.models.Image = undefined;
public _uploadedAvatar:common.models.Image;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down
22 changes: 11 additions & 11 deletions app/src/common/models/user/userProfileModel.ts
Expand Up @@ -11,17 +11,17 @@ module common.models {
dob: this.castDate,
};

public userId:string = undefined;
public dob:Date = undefined;
public mobile:string = undefined;
public phone:string = undefined;
public gender:string = undefined;
public about:string = undefined;
public facebook:string = undefined;
public twitter:string = undefined;
public pinterest:string = undefined;
public instagram:string = undefined;
public website:string = undefined;
public userId:string;
public dob:Date;
public mobile:string;
public phone:string;
public gender:string;
public about:string;
public facebook:string;
public twitter:string;
public pinterest:string;
public instagram:string;
public website:string;

public static genderOptions:IGenderOption[] = [
{label: 'Male', value: 'M'},
Expand Down
6 changes: 3 additions & 3 deletions app/src/common/models/user/userSocialLoginModel.ts
Expand Up @@ -6,9 +6,9 @@ module common.models {
public static facebookType = 'facebook';
public static providerTypes:string[] = [UserSocialLogin.googleType, UserSocialLogin.facebookType];

public userId:string = undefined;
public provider:string = undefined;
public token:string = undefined;
public userId:string;
public provider:string;
public token:string;

constructor(data:any, exists:boolean = false) {
super(data, exists);
Expand Down

0 comments on commit 5628bf7

Please sign in to comment.