-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: all shered components and dtos
- Loading branch information
Showing
26 changed files
with
412 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Expose, Type } from 'class-transformer'; | ||
import { IsDefined } from 'class-validator'; | ||
import { GroupDto } from 'src/core/groups/dtos'; | ||
import { AccountBasicDto, SystemStatus } from 'src/libs/shared'; | ||
import { RoleDto } from 'src/core/role/dtos/role.dto'; | ||
|
||
export class UserAccountDto extends AccountBasicDto { | ||
@Expose() | ||
firstName?: string; | ||
|
||
@Expose() | ||
lastName?: string; | ||
|
||
@Expose() | ||
email!: string; | ||
|
||
@Expose() | ||
@Type(() => RoleDto) | ||
role!: RoleDto[]; | ||
|
||
@Expose() | ||
@Type(() => GroupDto) | ||
groups!: GroupDto[]; | ||
|
||
@Expose() | ||
@IsDefined() | ||
status!: SystemStatus; | ||
|
||
get fullName(): string { | ||
const fullName = [this.firstName, this.lastName].filter(Boolean).join(' '); | ||
if (fullName) { | ||
return fullName; | ||
} else { | ||
return this.email; | ||
} | ||
} | ||
|
||
get initials(): string { | ||
if (this.firstName && this.lastName) { | ||
return `${this.firstName[0].toUpperCase()}${this.lastName[0].toUpperCase()}`; | ||
} else if (this.firstName) { | ||
return `${this.firstName[0].toUpperCase()}`; | ||
} else if (this.lastName) { | ||
return `${this.lastName[0].toUpperCase()}`; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './account.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Optional } from '@nestjs/common'; | ||
import { Expose } from 'class-transformer'; | ||
import { IsNotEmpty, IsString, MaxLength } from 'class-validator'; | ||
import { FieldConstraints } from 'src/libs/shared'; | ||
|
||
export class CreateGroupDto { | ||
@Expose() | ||
@IsString() | ||
@IsNotEmpty() | ||
@MaxLength(FieldConstraints.FIRST_NAME.MAX_LENGTH) | ||
name!: string; | ||
|
||
@Expose() | ||
@Optional() | ||
@IsString() | ||
@MaxLength(FieldConstraints.COURSE_NAME.MAX_LENGTH) | ||
courseName?: string; | ||
|
||
@Expose() | ||
@Optional() | ||
@IsString() | ||
@MaxLength(FieldConstraints.DESCRIPTION.MAX_LENGTH) | ||
description?: string; | ||
|
||
@Expose() | ||
@IsString() | ||
@IsNotEmpty() | ||
avatar!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Expose } from 'class-transformer'; | ||
import { IsDefined } from 'class-validator'; | ||
import { SystemStatus } from 'src/libs/shared'; | ||
|
||
export class GroupDto { | ||
@Expose() | ||
name!: string; | ||
|
||
@Expose() | ||
courseName?: string; | ||
|
||
@Expose() | ||
description?: string; | ||
|
||
@Expose() | ||
avatar!: string; | ||
|
||
@Expose() | ||
code!: string; | ||
|
||
@IsDefined() | ||
@Expose() | ||
status!: SystemStatus; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './create-group.dto'; | ||
export * from './join-group.dto'; | ||
export * from './group.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IsNotEmpty, IsString, Matches, MaxLength } from 'class-validator'; | ||
|
||
export class JoinGroupDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
userId!: string; | ||
//TODO: change match & length decorator to use appfield contraints | ||
@IsString() | ||
@IsNotEmpty() | ||
@MaxLength(20) | ||
@Matches(/^[aA-z0-9-]+$/) | ||
code!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './role.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Expose, Type } from 'class-transformer'; | ||
import { IsDefined } from 'class-validator'; | ||
import { Action, BaseDto, Subject, SystemStatus } from 'src/libs/shared'; | ||
|
||
export class PermissionRule { | ||
@Expose() | ||
action!: Action; | ||
|
||
@Expose() | ||
subject!: Subject; | ||
} | ||
|
||
export class RoleDto extends BaseDto { | ||
@Expose() | ||
name!: string; | ||
|
||
@Expose() | ||
code!: string; | ||
|
||
@Expose() | ||
@Type(() => PermissionRule) | ||
permissions!: PermissionRule[]; | ||
|
||
@Expose() | ||
@IsDefined() | ||
status!: SystemStatus; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Expose } from 'class-transformer'; | ||
import { BasicDto } from './basic.dto'; | ||
|
||
export abstract class AccountBasicDto extends BasicDto { | ||
@Expose() | ||
username!: string; | ||
|
||
@Expose() | ||
avatarUrl?: string; | ||
|
||
abstract fullName: string; | ||
|
||
abstract initials: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Exclude, Expose, Transform, Type } from 'class-transformer'; | ||
import { BasicDto } from './basic.dto'; | ||
import { AccountBasicDto } from './account-basic.dto'; | ||
@Exclude() | ||
export abstract class BaseDto extends BasicDto { | ||
@Expose() | ||
@Transform( | ||
({ value, obj }) => { | ||
if (obj.createdBy) { | ||
return value; | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
{ toClassOnly: true }, | ||
) | ||
@Type(() => Date) | ||
createdAt?: Date; | ||
|
||
@Expose() | ||
@Type(() => Date) | ||
updatedAt!: Date; | ||
|
||
@Expose() | ||
@Type(() => AccountBasicDto) | ||
createdBy?: AccountBasicDto; | ||
|
||
@Expose() | ||
@Type(() => AccountBasicDto) | ||
updatedBy!: AccountBasicDto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Exclude, Expose, Transform } from 'class-transformer'; | ||
@Exclude() | ||
export abstract class BasicDto { | ||
@Expose() | ||
@Transform( | ||
({ value, obj }) => { | ||
if (value && typeof value === 'string') { | ||
return value; | ||
} else if (obj._id) { | ||
return typeof obj._id === 'string' ? obj._id : obj._id.toString(); | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
{ toClassOnly: true }, | ||
) | ||
id!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './base.dto'; | ||
export * from './basic.dto'; | ||
export * from './account-basic.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export enum EventType { | ||
ZAJĘCIA = 'Zajęcia', | ||
SPOTKANIE = 'Spotkanie', | ||
EGZAMIN = 'Egzamin', | ||
KOLOKWIUM = 'Kolokwium', | ||
ODWOLANIE_ZAJEC = 'Odwołanie zajęć', | ||
POPRAWKA = 'Poprawka', | ||
INNE = 'Inne', | ||
CLASSES = 'Zajęcia', | ||
MEETING = 'Spotkanie', | ||
EXAM = 'Egzamin', | ||
QUIZ = 'Kolokwium', | ||
CLASS_CANCELLATION = 'Odwołanie zajęć', | ||
RETAKE = 'Poprawka', | ||
OTHER = 'Inne', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './consts'; | ||
export * from './enums'; | ||
export * from './dtos'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { Document } from 'mongoose'; | ||
import { Action, Subject, FieldConstraints } from 'src/libs/shared'; | ||
|
||
export type AppPermissionsDocument = AppPermissions & Document; | ||
|
||
@Schema() | ||
export class AppPermissions { | ||
@Prop({ | ||
required: true, | ||
lowercase: true, | ||
trim: true, | ||
enum: Action, | ||
maxlength: FieldConstraints.ACTION.MAX_LENGTH, | ||
}) | ||
action!: Action; | ||
|
||
@Prop({ | ||
required: true, | ||
lowercase: true, | ||
trim: true, | ||
enum: Subject, | ||
maxlength: FieldConstraints.SUBJECT.MAX_LENGTH, | ||
}) | ||
subject!: Subject; | ||
} | ||
|
||
export const AppPermissionsSchema = | ||
SchemaFactory.createForClass(AppPermissions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Prop } from '@nestjs/mongoose'; | ||
import { SystemStatus } from 'src/libs/shared'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
export abstract class BaseClass { | ||
@Prop({ default: uuid, readonly: true, select: false }) | ||
_id!: string; | ||
|
||
get id(): string { | ||
return this._id; | ||
} | ||
|
||
@Prop({ required: true, default: SystemStatus.ACTIVE, enum: SystemStatus }) | ||
status!: SystemStatus; | ||
|
||
@Prop({ required: true, default: Date.now, readonly: true }) | ||
createdAt!: Date; | ||
|
||
@Prop({ required: true, default: Date.now }) | ||
updatedAt!: Date; | ||
} |
Oops, something went wrong.