Skip to content

Commit

Permalink
feat: add note schema
Browse files Browse the repository at this point in the history
Signed-off-by: iverly <github@iverly.net>
  • Loading branch information
iverly committed Nov 27, 2023
1 parent 8370b32 commit d4a98f6
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 5 deletions.
Empty file removed config/keto/namespaces/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions config/keto/namespaces/notes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": 1,
"name": "notes"
}
4 changes: 4 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from './lib/id-token';

// Generated by prisma
export * from './lib/generated/classes/note/dto/index';
export * from './lib/generated/classes/note/entities/index';
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export class ConnectNoteDto {
id: string;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import {Type} from 'class-transformer'
import {IsNotEmpty,IsString,Length} from 'class-validator'
import {ApiProperty,getSchemaPath} from '@nestjs/swagger'




export class CreateNoteDto {
@ApiProperty({
description: `The note title`,
example: `My note`,
maxLength: 40,
minLength: 3,
})
@IsNotEmpty()
@IsString()
@Length(3, 40)
title: string;
@ApiProperty({
description: `The note body`,
example: `This is my note`,
maxLength: 200,
minLength: 3,
})
@IsNotEmpty()
@IsString()
@Length(3, 200)
body: string;
}
5 changes: 5 additions & 0 deletions packages/types/src/lib/generated/classes/note/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export * from './connect-note.dto';
export * from './create-note.dto';
export * from './update-note.dto';
export * from './note.dto';
31 changes: 31 additions & 0 deletions packages/types/src/lib/generated/classes/note/dto/note.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import {ApiProperty} from '@nestjs/swagger'


export class NoteDto {
@ApiProperty({
description: `The note id`,
example: `b1774d2f-05f7-4ea4-b427-0d808bdca583`,
})
id: string ;
@ApiProperty({
description: `The note title`,
example: `My note`,
maxLength: 40,
minLength: 3,
})
title: string ;
@ApiProperty({
description: `The note body`,
example: `This is my note`,
maxLength: 200,
minLength: 3,
})
body: string ;
@ApiProperty({
description: `When the project was created`,
type: `string`,
format: `date-time`,
})
createdAt: Date ;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import {Type} from 'class-transformer'
import {IsOptional,IsString,Length} from 'class-validator'
import {ApiProperty} from '@nestjs/swagger'




export class UpdateNoteDto {
@ApiProperty({
description: `The note title`,
example: `My note`,
maxLength: 40,
minLength: 3,
})
@IsOptional()
@IsString()
@Length(3, 40)
title?: string;
@ApiProperty({
description: `The note body`,
example: `This is my note`,
maxLength: 200,
minLength: 3,
})
@IsOptional()
@IsString()
@Length(3, 200)
body?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export * from './note.entity';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import {ApiProperty} from '@nestjs/swagger'


export class Note {
@ApiProperty({
description: `The note id`,
example: `b1774d2f-05f7-4ea4-b427-0d808bdca583`,
})
id: string ;
@ApiProperty({
description: `The note title`,
example: `My note`,
maxLength: 40,
minLength: 3,
})
title: string ;
@ApiProperty({
description: `The note body`,
example: `This is my note`,
maxLength: 200,
minLength: 3,
})
body: string ;
@ApiProperty({
description: `When the project was created`,
type: `string`,
format: `date-time`,
})
createdAt: Date ;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export interface IConnectNoteAttributes {
id: string;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@






export interface ICreateNoteAttributes {
title: string;
body: string;
}
5 changes: 5 additions & 0 deletions packages/types/src/lib/generated/interfaces/note/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export * from './connect-note.dto';
export * from './create-note.dto';
export * from './update-note.dto';
export * from './note.dto';
10 changes: 10 additions & 0 deletions packages/types/src/lib/generated/interfaces/note/dto/note.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@




export interface NoteAttributes {
id: string ;
title: string ;
body: string ;
createdAt: Date ;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@






export interface IUpdateNoteAttributes {
title?: string;
body?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export * from './note.entity';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@




export interface INote {
id: string ;
title: string ;
body: string ;
createdAt: Date ;
}
9 changes: 9 additions & 0 deletions prisma/migrations/20231127140140_add_notes/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "notes" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"body" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "notes_pkey" PRIMARY KEY ("id")
);
2 changes: 1 addition & 1 deletion prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
provider = "postgresql"
26 changes: 22 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,26 @@ datasource db {
////////////////////////////////////////////////
// Model definitions //
////////////////////////////////////////////////
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
model Note {
/// @DtoReadOnly
/// @description The note id
/// @example b1774d2f-05f7-4ea4-b427-0d808bdca583
id String @id @default(uuid())
/// @description The note title
/// @example My note
/// @minLength 3
/// @maxLength 40
/// @Length(3, 40)
title String
/// @description The note body
/// @example This is my note
/// @minLength 3
/// @maxLength 200
/// @Length(3, 200)
body String
/// @DtoReadOnly
/// @description When the project was created
createdAt DateTime @default(now()) @map("created_at")
@@map("notes")
}

0 comments on commit d4a98f6

Please sign in to comment.