Skip to content

Commit

Permalink
feat(api): adding profile sub-module
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Feb 18, 2019
1 parent 04c5183 commit 45eeca0
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 85 deletions.
80 changes: 31 additions & 49 deletions .deploy/keycloak/realm-manual-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,72 @@
{
"username": "ngxadmin",
"enabled": true,
"firstName" : "ngxadmin",
"lastName" : "demo",
"email" : "[email protected]",
"firstName": "ngxadmin",
"lastName": "demo",
"email": "[email protected]",
"credentials": [
{
"type": "password",
"value": "ngxadmin"
}
],
"realmRoles": [
"ROLE_ADMIN"
]
"realmRoles": ["ROLE_ADMIN"]
},
{
"username": "sumo",
"enabled": true,
"firstName" : "sumo",
"lastName" : "demo",
"email" : "[email protected]",
"firstName": "sumo",
"lastName": "demo",
"email": "[email protected]",
"credentials": [
{
"type": "password",
"value": "demo"
}
],
"realmRoles": [
"ROLE_USER"
]
"realmRoles": ["ROLE_USER"]
},
{
"username": "sumo1",
"enabled": true,
"firstName" : "sumo1",
"lastName" : "demo",
"email" : "[email protected]",
"firstName": "sumo1",
"lastName": "demo",
"email": "[email protected]",
"credentials": [
{
"type": "password",
"value": "demo"
}
],
"realmRoles": [
"ROLE_USER"
]
"realmRoles": ["ROLE_USER"]
},
{
"username": "sumo2",
"enabled": true,
"firstName" : "sumo2",
"lastName" : "demo",
"email" : "[email protected]",
"firstName": "sumo2",
"lastName": "demo",
"email": "[email protected]",
"credentials": [
{
"type": "password",
"value": "demo"
}
],
"realmRoles": [
"ROLE_USER"
]
"realmRoles": ["ROLE_USER"]
},
{
"username": "sumo3",
"enabled": true,
"firstName" : "sumo3",
"lastName" : "demo",
"email" : "[email protected]",
"firstName": "sumo3",
"lastName": "demo",
"email": "[email protected]",
"credentials": [
{
"type": "password",
"value": "demo"
}
],
"realmRoles": [
"ROLE_USER"
]
"realmRoles": ["ROLE_USER"]
}
],
"roles": {
Expand All @@ -95,35 +85,27 @@
}
]
},
"defaultRoles": [
"ROLE_USER"
],
"defaultRoles": ["ROLE_USER"],
"clients": [
{
"clientId": "ngxapp",
"enabled": true,
"implicitFlowEnabled" : true,
"directAccessGrantsEnabled" : true,
"implicitFlowEnabled": true,
"directAccessGrantsEnabled": true,
"publicClient": true,
"redirectUris": [
"*"
],
"webOrigins": [
"*"
]
"rootUrl": "http://localhost:4200",
"redirectUris": ["*"],
"webOrigins": ["*"]
},
{
"clientId": "ngxapi",
"enabled": true,
"implicitFlowEnabled" : true,
"directAccessGrantsEnabled" : true,
"implicitFlowEnabled": true,
"directAccessGrantsEnabled": true,
"publicClient": true,
"redirectUris": [
"*"
],
"webOrigins": [
"*"
]
"rootUrl": "http://localhost:3000",
"redirectUris": ["*"],
"webOrigins": ["*"]
}
]
}
2 changes: 2 additions & 0 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UserModule } from './user';
import { AppController } from './app.controller';
import { NotificationsModule } from './notifications';
import { ExternalModule } from './external';
import { CacheModule } from './cache';

@Module({
imports: [
Expand All @@ -24,6 +25,7 @@ import { ExternalModule } from './external';
{ path: '/external', module: ExternalModule },
]),
CoreModule,
CacheModule,
AuthModule,
UserModule,
// AccountModule,
Expand Down
Empty file.
17 changes: 17 additions & 0 deletions apps/api/src/app/user/profile/dto/create-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IsEnum, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { ApiModelPropertyOptional } from '@nestjs/swagger';
import { Gender } from '@ngx-starter-kit/models';

export class CreateProfileDto {
@ApiModelPropertyOptional({ type: String, enum: Gender, default: Gender.UNKNOW })
@IsOptional()
@IsEnum(Gender)
gender?: Gender;

@ApiModelPropertyOptional({ type: String, minLength: 10, maxLength: 20 })
@IsOptional()
@IsString()
@MinLength(10)
@MaxLength(20)
mobilePhone?: string;
}
65 changes: 45 additions & 20 deletions apps/api/src/app/user/profile/image.entity.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { Column, CreateDateColumn, Entity, ManyToOne } from 'typeorm';
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional } from 'class-validator';
import { Transform } from 'class-transformer';

// TODO: https://github.com/nicolaspearson/salespal/blob/master/backend/src/controllers/StockImageController.ts
// TODO: https://github.com/mkatrenik/assignar
// TODO: https://steemit.com/utopian-io/@morningtundra/storing-and-retreiving-images-in-mongodb-with-nodejs
import { Base } from '../../core/entities/base.entity';
import { User } from '../../auth/user.entity';
import { Image as IImage, ImageType } from '@ngx-starter-kit/models';

@Entity('image')
export class Image {
@PrimaryGeneratedColumn()
id: number;

@Column({ length: 200 })
export class Image extends Base implements IImage {
@ApiModelProperty({ type: String, minLength: 1, maxLength: 100 })
@Column({ length: 100 })
title: string;

@Column('bytea')
image: any;

@Column()
@ApiModelProperty({ type: String, enum: ImageType, default: ImageType.Profile })
@Column({ type: 'enum', enum: ImageType, default: ImageType.Profile })
@IsEnum(ImageType)
type: ImageType;

// contentType?
// size?
}
@ApiModelProperty({ type: User })
@ManyToOne(type => User, user => user.images, { onDelete: 'CASCADE', nullable: false })
user: User;

@ApiModelProperty({ type: 'string', format: 'date-time', example: '2018-11-21T06:20:32.232Z' })
@CreateDateColumn({ type: 'timestamptz' })
createdAt?: Date;

@ApiModelPropertyOptional({ type: String })
@IsOptional()
@Transform(value => value.toString('base64'), { toPlainOnly: true })
@Column({ type: 'bytea', nullable: true })
data?: Buffer;

@ApiModelPropertyOptional({ type: String })
@IsOptional()
@Column({ nullable: true })
checksum?: string;

@ApiModelPropertyOptional({ type: String })
@IsOptional()
@Column({ nullable: true })
mimeType?: string;

@ApiModelPropertyOptional({ type: Number })
@IsOptional()
@Column({ nullable: true })
size?: number;

export enum ImageType {
Profile,
Icon,
Avatar,
@ApiModelPropertyOptional({ type: String, maxLength: 500 })
@IsOptional()
@Column({ length: 500, nullable: true })
url?: string;
}
Loading

0 comments on commit 45eeca0

Please sign in to comment.