File tree 9 files changed +91
-13
lines changed
libs/cattalog/src/lib/modeling
9 files changed +91
-13
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ export async function up(knex: Knex) {
25
25
} ) ;
26
26
27
27
await knex . schema . table ( 'book_instance' , ( t ) => {
28
- t . foreign ( 'book_id' ) . references ( 'id' ) . inTable ( 'book' ) ;
28
+ t . foreign ( 'book_id' ) . references ( 'id' ) . inTable ( 'book' )
29
+ . onDelete ( 'CASCADE' ) . onUpdate ( 'CASCADE' ) ;
29
30
} ) ;
30
31
}
31
32
Original file line number Diff line number Diff line change
1
+ import { Knex } from 'knex' ;
2
+ import { BookModel } from '../../models/book.db.model' ;
3
+
4
+ export async function seed ( knex : Knex ) : Promise < any > {
5
+ await BookModel . query ( knex ) . del ( ) ;
6
+ await BookModel . query ( knex ) . insert ( [
7
+ {
8
+ name : 'Workout' ,
9
+ isbn : '1' ,
10
+ category : 'history' ,
11
+ available_quantity : 10 ,
12
+ total : 10 ,
13
+ lost : 0 ,
14
+ } ,
15
+ {
16
+ name : '10 funny' ,
17
+ isbn : '2' ,
18
+ category : 'physical' ,
19
+ available_quantity : 10 ,
20
+ total : 10 ,
21
+ lost : 0 ,
22
+ } ,
23
+ {
24
+ name : 'Web programing' ,
25
+ isbn : '3' ,
26
+ category : 'history' ,
27
+ available_quantity : 10 ,
28
+ total : 10 ,
29
+ lost : 0 ,
30
+ } ,
31
+ {
32
+ name : 'How to talk funny with people' ,
33
+ isbn : '4' ,
34
+ category : 'biology' ,
35
+ available_quantity : 10 ,
36
+ total : 10 ,
37
+ lost : 0 ,
38
+ } ,
39
+ {
40
+ name : 'Talk easily' ,
41
+ isbn : '5' ,
42
+ category : 'geography' ,
43
+ available_quantity : 10 ,
44
+ total : 10 ,
45
+ lost : 0 ,
46
+ }
47
+ ] ) ;
48
+ }
Original file line number Diff line number Diff line change
1
+ import { Knex } from 'knex' ;
2
+ import { BookInstanceModel } from '../../models/book-instance.db.model' ;
3
+
4
+ export async function seed ( knex : Knex ) : Promise < any > {
5
+ await BookInstanceModel . query ( knex ) . delete ( ) ;
6
+ await BookInstanceModel . query ( knex ) . insert ( [
7
+ {
8
+ status : 'activated' ,
9
+ book_id : 2 ,
10
+ } ,
11
+ {
12
+ status : 'activated' ,
13
+ book_id : 1 ,
14
+ } ,
15
+ {
16
+ status : 'activated' ,
17
+ book_id : 1 ,
18
+ } ,
19
+ {
20
+ status : 'activated' ,
21
+ book_id : 2 ,
22
+ } ,
23
+ ] ) ;
24
+ }
Original file line number Diff line number Diff line change 1
- import * as Knex from 'knex';
1
+ import { Knex } from 'knex';
2
2
3
3
const tableName = '';
4
4
Original file line number Diff line number Diff line change 1
- import * as Knex from 'knex';
1
+ import { Knex } from 'knex';
2
2
3
3
export async function seed(knex: Knex): Promise<any> {
4
4
}
Original file line number Diff line number Diff line change 1
- import { BookModel } from 'apps/library/src/app/models/book.db.model' ;
2
1
import { Model } from 'objection' ;
3
2
import { BaseModel } from './base.model' ;
4
- import { BookStatus } from '../../../../../libs/cattalog/src/lib/modeling/book-instance.modeling' ;
3
+ import { BookStatus } from '../../../../../libs/cattalog/src/lib/modeling/BookStatus.type' ;
4
+ import { BookModel } from './book.db.model' ;
5
+ import { number } from 'fp-ts-std' ;
5
6
6
- export class BookInstanceModel extends BaseModel {
7
+ export class BookInstanceModel extends BaseModel {
7
8
static tableName = 'book_instance' ;
8
9
9
10
status : BookStatus ;
11
+ book : BookModel ;
12
+ book_id : number ;
10
13
11
14
static RelationMappings = {
12
15
owner : {
13
16
relation : Model . BelongsToOneRelation ,
14
- modelClass : BookModel ,
17
+ modelClass : ` ${ __dirname } /book.db.model` ,
15
18
join : {
16
19
from : 'book_instance.book_id' ,
17
20
to : 'book.id' ,
18
- }
19
- }
20
- }
21
+ } ,
22
+ } ,
23
+ } ;
21
24
}
Original file line number Diff line number Diff line change 1
- import { BookInstance } from 'libs/catalogue/src/lib/book-instance' ;
2
1
import { Model } from 'objection' ;
3
2
import { BaseModel } from './base.model' ;
3
+ import { BookInstanceModel } from './book-instance.db.model' ;
4
4
5
5
export class BookModel extends BaseModel {
6
6
static tableName = 'book' ;
@@ -17,7 +17,7 @@ export class BookModel extends BaseModel{
17
17
static RelationMappings = {
18
18
owner : {
19
19
relation : Model . HasManyRelation ,
20
- modelClass : BookInstance ,
20
+ modelClass : BookInstanceModel ,
21
21
join : {
22
22
from : 'book.id' ,
23
23
to : 'book_instance.book_id'
Original file line number Diff line number Diff line change
1
+
2
+ export type BookStatus = "achived" | "activated" | "pending"
Original file line number Diff line number Diff line change 1
1
import { Uuid } from "@library/shared/doomain"
2
2
import { Book } from './book.modelling' ;
3
+ import { BookStatus } from './BookStatus.type' ;
3
4
4
- export type BookStatus = "achived" | "activated" | "pending"
5
5
6
6
export class BookInstance {
7
7
id : Uuid ;
You can’t perform that action at this time.
0 commit comments