From 73343a347743770b45b41906d1996ea2e51250d1 Mon Sep 17 00:00:00 2001 From: NLNM-0-0 Date: Sun, 24 Dec 2023 17:08:17 +0700 Subject: [PATCH 1/2] fix: delete cookie for be dev: add avatar for user --- .../common/app_error.go | 7 -- book-store-management-backend/common/const.go | 8 -- book-store-management-backend/docs/docs.go | 111 +++++++++++++----- .../docs/swagger.json | 111 +++++++++++++----- .../docs/swagger.yaml | 77 ++++++++---- .../middleware/authorize.go | 10 +- .../middleware/get_cookie_handler.go | 27 ----- .../module/user/userbiz/refresh_token.go | 4 +- .../module/user/usermodel/req_create_user.go | 4 + .../user/usermodel/req_update_info_user.go | 4 + .../module/user/usermodel/res_user.go | 1 + .../module/user/usermodel/user.go | 6 + .../module/user/userstore/list.go | 2 +- .../user/usertransport/ginuser/login.go | 16 +-- .../usertransport/ginuser/refresh_token.go | 21 ++-- .../user/usertransport/ginuser/route.go | 12 +- .../user/usertransport/ginuser/sign_out.go | 29 ----- 17 files changed, 253 insertions(+), 197 deletions(-) delete mode 100644 book-store-management-backend/middleware/get_cookie_handler.go delete mode 100644 book-store-management-backend/module/user/usertransport/ginuser/sign_out.go diff --git a/book-store-management-backend/common/app_error.go b/book-store-management-backend/common/app_error.go index f2ff6cf..fb8d480 100755 --- a/book-store-management-backend/common/app_error.go +++ b/book-store-management-backend/common/app_error.go @@ -103,14 +103,7 @@ func ErrRecordNotFound() *AppError { ) } -var ErrTokenExpired = NewCustomError( - errTokenExpired, - fmt.Sprintf("Đã có lỗi xảy ra. Xin hãy đăng nhập lại."), - fmt.Sprintf("ErrTokenExpired"), -) - var ( errRecordNotFound = errors.New("record not found") errIdIsTooLong = errors.New("id is too long") - errTokenExpired = errors.New("token is expired") ) diff --git a/book-store-management-backend/common/const.go b/book-store-management-backend/common/const.go index 19d81cf..acf2083 100755 --- a/book-store-management-backend/common/const.go +++ b/book-store-management-backend/common/const.go @@ -85,12 +85,4 @@ const RoleAdminId = "admin" const DefaultPass = "app123" -const AccessTokenStrInCookie = "accessToken" -const RefreshTokenStrInCookie = "refreshToken" - const CurrentUserStr = "current_user" -const AccessTokenStr = "access_token" -const RefreshTokenStr = "refresh_token" - -const MaxAgeAccessToken = 60 * 60 * 24 -const MaxAgeRefreshToken = 60 * 60 * 24 * 3 diff --git a/book-store-management-backend/docs/docs.go b/book-store-management-backend/docs/docs.go index e9b14c6..81da36b 100644 --- a/book-store-management-backend/docs/docs.go +++ b/book-store-management-backend/docs/docs.go @@ -1219,9 +1219,9 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "status of response", + "description": "user token", "schema": { - "$ref": "#/definitions/common.ResSuccess" + "$ref": "#/definitions/usermodel.Account" } }, "400": { @@ -1346,11 +1346,22 @@ const docTemplate = `{ "auth" ], "summary": "Refresh token", + "parameters": [ + { + "description": "refreshToken", + "name": "refreshToken", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/usermodel.ReqRefreshToken" + } + } + ], "responses": { "200": { - "description": "status of response", + "description": "user token", "schema": { - "$ref": "#/definitions/common.ResSuccess" + "$ref": "#/definitions/usermodel.AccountWithoutRefresh" } }, "400": { @@ -1660,34 +1671,6 @@ const docTemplate = `{ } } }, - "/signOut": { - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "auth" - ], - "summary": "SignOut", - "responses": { - "200": { - "description": "status of response", - "schema": { - "$ref": "#/definitions/common.ResSuccess" - } - }, - "400": { - "description": "error", - "schema": { - "$ref": "#/definitions/common.AppError" - } - } - } - } - }, "/suppliers": { "get": { "security": [ @@ -2790,6 +2773,10 @@ const docTemplate = `{ "type": "string", "example": "bookId" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "importPrice": { "type": "integer", "example": 100000 @@ -4505,6 +4492,42 @@ const docTemplate = `{ } } }, + "tokenprovider.Token": { + "type": "object", + "properties": { + "created": { + "type": "string", + "example": "2023-12-03T15:02:19.62113565Z" + }, + "expiry": { + "type": "integer", + "example": 2592000 + }, + "token": { + "type": "string", + "example": "token" + } + } + }, + "usermodel.Account": { + "type": "object", + "properties": { + "accessToken": { + "$ref": "#/definitions/tokenprovider.Token" + }, + "refreshToken": { + "$ref": "#/definitions/tokenprovider.Token" + } + } + }, + "usermodel.AccountWithoutRefresh": { + "type": "object", + "properties": { + "accessToken": { + "$ref": "#/definitions/tokenprovider.Token" + } + } + }, "usermodel.Filter": { "type": "object", "properties": { @@ -4529,6 +4552,10 @@ const docTemplate = `{ "type": "string", "example": "a@gmail.com" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "name": { "type": "string", "example": "Nguyễn Văn A" @@ -4556,6 +4583,14 @@ const docTemplate = `{ } } }, + "usermodel.ReqRefreshToken": { + "type": "object", + "properties": { + "refreshToken": { + "type": "string" + } + } + }, "usermodel.ReqResetPasswordUser": { "type": "object", "properties": { @@ -4572,6 +4607,10 @@ const docTemplate = `{ "type": "string", "example": "bỏ trường này nếu không muốn update địa chỉ" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "name": { "type": "string", "example": "bỏ trường này nếu không muốn update tên" @@ -4683,6 +4722,10 @@ const docTemplate = `{ "type": "string", "example": "user id" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "isActive": { "type": "boolean", "example": true @@ -4728,6 +4771,10 @@ const docTemplate = `{ "type": "string", "example": "user id" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "isActive": { "type": "boolean", "example": true diff --git a/book-store-management-backend/docs/swagger.json b/book-store-management-backend/docs/swagger.json index 07f5912..c470444 100644 --- a/book-store-management-backend/docs/swagger.json +++ b/book-store-management-backend/docs/swagger.json @@ -1213,9 +1213,9 @@ ], "responses": { "200": { - "description": "status of response", + "description": "user token", "schema": { - "$ref": "#/definitions/common.ResSuccess" + "$ref": "#/definitions/usermodel.Account" } }, "400": { @@ -1340,11 +1340,22 @@ "auth" ], "summary": "Refresh token", + "parameters": [ + { + "description": "refreshToken", + "name": "refreshToken", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/usermodel.ReqRefreshToken" + } + } + ], "responses": { "200": { - "description": "status of response", + "description": "user token", "schema": { - "$ref": "#/definitions/common.ResSuccess" + "$ref": "#/definitions/usermodel.AccountWithoutRefresh" } }, "400": { @@ -1654,34 +1665,6 @@ } } }, - "/signOut": { - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "auth" - ], - "summary": "SignOut", - "responses": { - "200": { - "description": "status of response", - "schema": { - "$ref": "#/definitions/common.ResSuccess" - } - }, - "400": { - "description": "error", - "schema": { - "$ref": "#/definitions/common.AppError" - } - } - } - } - }, "/suppliers": { "get": { "security": [ @@ -2784,6 +2767,10 @@ "type": "string", "example": "bookId" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "importPrice": { "type": "integer", "example": 100000 @@ -4499,6 +4486,42 @@ } } }, + "tokenprovider.Token": { + "type": "object", + "properties": { + "created": { + "type": "string", + "example": "2023-12-03T15:02:19.62113565Z" + }, + "expiry": { + "type": "integer", + "example": 2592000 + }, + "token": { + "type": "string", + "example": "token" + } + } + }, + "usermodel.Account": { + "type": "object", + "properties": { + "accessToken": { + "$ref": "#/definitions/tokenprovider.Token" + }, + "refreshToken": { + "$ref": "#/definitions/tokenprovider.Token" + } + } + }, + "usermodel.AccountWithoutRefresh": { + "type": "object", + "properties": { + "accessToken": { + "$ref": "#/definitions/tokenprovider.Token" + } + } + }, "usermodel.Filter": { "type": "object", "properties": { @@ -4523,6 +4546,10 @@ "type": "string", "example": "a@gmail.com" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "name": { "type": "string", "example": "Nguyễn Văn A" @@ -4550,6 +4577,14 @@ } } }, + "usermodel.ReqRefreshToken": { + "type": "object", + "properties": { + "refreshToken": { + "type": "string" + } + } + }, "usermodel.ReqResetPasswordUser": { "type": "object", "properties": { @@ -4566,6 +4601,10 @@ "type": "string", "example": "bỏ trường này nếu không muốn update địa chỉ" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "name": { "type": "string", "example": "bỏ trường này nếu không muốn update tên" @@ -4677,6 +4716,10 @@ "type": "string", "example": "user id" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "isActive": { "type": "boolean", "example": true @@ -4722,6 +4765,10 @@ "type": "string", "example": "user id" }, + "img": { + "type": "string", + "example": "https://picsum.photos/200" + }, "isActive": { "type": "boolean", "example": true diff --git a/book-store-management-backend/docs/swagger.yaml b/book-store-management-backend/docs/swagger.yaml index 672da4d..6359f8c 100644 --- a/book-store-management-backend/docs/swagger.yaml +++ b/book-store-management-backend/docs/swagger.yaml @@ -159,6 +159,9 @@ definitions: id: example: bookId type: string + img: + example: https://picsum.photos/200 + type: string importPrice: example: 100000 type: integer @@ -1311,6 +1314,30 @@ definitions: example: "0123456789" type: string type: object + tokenprovider.Token: + properties: + created: + example: "2023-12-03T15:02:19.62113565Z" + type: string + expiry: + example: 2592000 + type: integer + token: + example: token + type: string + type: object + usermodel.Account: + properties: + accessToken: + $ref: '#/definitions/tokenprovider.Token' + refreshToken: + $ref: '#/definitions/tokenprovider.Token' + type: object + usermodel.AccountWithoutRefresh: + properties: + accessToken: + $ref: '#/definitions/tokenprovider.Token' + type: object usermodel.Filter: properties: active: @@ -1328,6 +1355,9 @@ definitions: email: example: a@gmail.com type: string + img: + example: https://picsum.photos/200 + type: string name: example: Nguyễn Văn A type: string @@ -1347,6 +1377,11 @@ definitions: example: app123 type: string type: object + usermodel.ReqRefreshToken: + properties: + refreshToken: + type: string + type: object usermodel.ReqResetPasswordUser: properties: userSenderPass: @@ -1358,6 +1393,9 @@ definitions: address: example: bỏ trường này nếu không muốn update địa chỉ type: string + img: + example: https://picsum.photos/200 + type: string name: example: bỏ trường này nếu không muốn update tên type: string @@ -1431,6 +1469,9 @@ definitions: id: example: user id type: string + img: + example: https://picsum.photos/200 + type: string isActive: example: true type: boolean @@ -1463,6 +1504,9 @@ definitions: id: example: user id type: string + img: + example: https://picsum.photos/200 + type: string isActive: example: true type: boolean @@ -2232,9 +2276,9 @@ paths: - application/json responses: "200": - description: status of response + description: user token schema: - $ref: '#/definitions/common.ResSuccess' + $ref: '#/definitions/usermodel.Account' "400": description: error schema: @@ -2304,13 +2348,20 @@ paths: post: consumes: - application/json + parameters: + - description: refreshToken + in: body + name: refreshToken + required: true + schema: + $ref: '#/definitions/usermodel.ReqRefreshToken' produces: - application/json responses: "200": - description: status of response + description: user token schema: - $ref: '#/definitions/common.ResSuccess' + $ref: '#/definitions/usermodel.AccountWithoutRefresh' "400": description: error schema: @@ -2504,24 +2555,6 @@ paths: summary: Update info role tags: - roles - /signOut: - post: - consumes: - - application/json - produces: - - application/json - responses: - "200": - description: status of response - schema: - $ref: '#/definitions/common.ResSuccess' - "400": - description: error - schema: - $ref: '#/definitions/common.AppError' - summary: SignOut - tags: - - auth /suppliers: get: consumes: diff --git a/book-store-management-backend/middleware/authorize.go b/book-store-management-backend/middleware/authorize.go index 557ec40..e40bd57 100755 --- a/book-store-management-backend/middleware/authorize.go +++ b/book-store-management-backend/middleware/authorize.go @@ -40,13 +40,11 @@ func RequireAuth(appCtx appctx.AppContext) func(ctx *gin.Context) { tokenProvider := jwt.NewTokenJWTProvider(appCtx.GetSecretKey()) return func(c *gin.Context) { - token := c.MustGet(common.AccessTokenStr).(string) + token, err := extractTokenFromHeaderString(c.GetHeader("Authorization")) - //token, err := extractTokenFromHeaderString(c.GetHeader("Authorization")) - - //if err != nil { - // panic(err) - //} + if err != nil { + panic(err) + } db := appCtx.GetMainDBConnection() diff --git a/book-store-management-backend/middleware/get_cookie_handler.go b/book-store-management-backend/middleware/get_cookie_handler.go deleted file mode 100644 index df186e5..0000000 --- a/book-store-management-backend/middleware/get_cookie_handler.go +++ /dev/null @@ -1,27 +0,0 @@ -package middleware - -import ( - "book-store-management-backend/common" - "github.com/gin-gonic/gin" -) - -func GetCookieHandler(cookiePath string, valuePath string, errReturn error) func(ctx *gin.Context) { - return func(c *gin.Context) { - value, err := c.Cookie(cookiePath) - if err != nil { - panic(errReturn) - } - c.Set(valuePath, value) - c.Next() - } -} - -func GetAccessTokenCookieHandler() func(ctx *gin.Context) { - return GetCookieHandler( - common.AccessTokenStrInCookie, common.AccessTokenStr, common.ErrTokenExpired) -} - -func GetRefreshTokenCookieHandler() func(ctx *gin.Context) { - return GetCookieHandler( - common.RefreshTokenStrInCookie, common.RefreshTokenStr, common.ErrTokenExpired) -} diff --git a/book-store-management-backend/module/user/userbiz/refresh_token.go b/book-store-management-backend/module/user/userbiz/refresh_token.go index 0c291c3..8da6a4a 100644 --- a/book-store-management-backend/module/user/userbiz/refresh_token.go +++ b/book-store-management-backend/module/user/userbiz/refresh_token.go @@ -26,8 +26,8 @@ func NewRefreshTokenBiz( } func (biz *refreshTokenBiz) RefreshToken( - ctx context.Context, refreshToken string) (*usermodel.AccountWithoutRefresh, error) { - payload, err := biz.tokenProvider.Validate(refreshToken) + ctx context.Context, refreshToken *usermodel.ReqRefreshToken) (*usermodel.AccountWithoutRefresh, error) { + payload, err := biz.tokenProvider.Validate(refreshToken.RefreshToken) if err != nil { panic(err) } diff --git a/book-store-management-backend/module/user/usermodel/req_create_user.go b/book-store-management-backend/module/user/usermodel/req_create_user.go index 9ea230b..9aee2df 100644 --- a/book-store-management-backend/module/user/usermodel/req_create_user.go +++ b/book-store-management-backend/module/user/usermodel/req_create_user.go @@ -13,6 +13,7 @@ type ReqCreateUser struct { Password string `json:"-" gorm:"column:password;"` Salt string `json:"-" gorm:"column:salt;"` RoleId string `json:"roleId" gorm:"column:roleId;" example:"role id"` + ImgUrl string `json:"img" gorm:"column:imgUrl" example:"https://picsum.photos/200"` } func (*ReqCreateUser) TableName() string { @@ -32,5 +33,8 @@ func (data *ReqCreateUser) Validate() error { if !common.ValidateNotNilId(&data.RoleId) { return ErrUserRoleInvalid } + if !common.ValidateUrl(data.ImgUrl) { + return ErrUserImageInvalid + } return nil } diff --git a/book-store-management-backend/module/user/usermodel/req_update_info_user.go b/book-store-management-backend/module/user/usermodel/req_update_info_user.go index 9dd78f7..a29b46f 100644 --- a/book-store-management-backend/module/user/usermodel/req_update_info_user.go +++ b/book-store-management-backend/module/user/usermodel/req_update_info_user.go @@ -6,6 +6,7 @@ type ReqUpdateInfoUser struct { Name *string `json:"name" gorm:"column:name;" example:"bỏ trường này nếu không muốn update tên"` Phone *string `json:"phone" gorm:"column:phone;" example:"bỏ trường này nếu không muốn update sđt"` Address *string `json:"address" gorm:"column:address;" example:"bỏ trường này nếu không muốn update địa chỉ"` + ImgUrl *string `json:"img" gorm:"column:imgUrl" example:"https://picsum.photos/200"` } func (*ReqUpdateInfoUser) TableName() string { @@ -19,5 +20,8 @@ func (data *ReqUpdateInfoUser) Validate() error { if data.Phone != nil && len(*data.Phone) != 0 && !common.ValidatePhone(*data.Phone) { return ErrUserPhoneInvalid } + if data.ImgUrl != nil && !common.ValidateUrl(*data.ImgUrl) { + return ErrUserImageInvalid + } return nil } diff --git a/book-store-management-backend/module/user/usermodel/res_user.go b/book-store-management-backend/module/user/usermodel/res_user.go index d5d5a3d..0cabdec 100644 --- a/book-store-management-backend/module/user/usermodel/res_user.go +++ b/book-store-management-backend/module/user/usermodel/res_user.go @@ -15,6 +15,7 @@ type ResUser struct { Salt string `json:"-" gorm:"column:salt;"` RoleId string `json:"-" gorm:"column:roleId;"` Role rolemodel.SimpleRole `json:"role" gorm:"foreignkey:roleId"` + ImgUrl string `json:"img" gorm:"column:imgUrl" example:"https://picsum.photos/200"` IsActive bool `json:"isActive" gorm:"column:isActive;" example:"true"` } diff --git a/book-store-management-backend/module/user/usermodel/user.go b/book-store-management-backend/module/user/usermodel/user.go index 12af3ad..952d615 100755 --- a/book-store-management-backend/module/user/usermodel/user.go +++ b/book-store-management-backend/module/user/usermodel/user.go @@ -16,6 +16,7 @@ type User struct { Salt string `json:"-" gorm:"column:salt;"` RoleId string `json:"-" gorm:"column:roleId;"` Role rolemodel.Role `json:"role" gorm:"foreignkey:roleId"` + ImgUrl string `json:"img" gorm:"column:imgUrl" example:"https://picsum.photos/200"` IsActive bool `json:"isActive" gorm:"column:isActive;" example:"true"` } @@ -74,6 +75,11 @@ var ( "Số điện thoại của người dùng không hợp lệ", "ErrUserPhoneInvalid", ) + ErrUserImageInvalid = common.NewCustomError( + errors.New("avatar of user is invalid"), + "Ảnh của người dùng không hợp lệ", + "ErrUserImageInvalid", + ) ErrUserEmailOrPasswordInvalid = common.NewCustomError( errors.New("email or password invalid"), "Email hoặc mật khẩu không hợp lệ", diff --git a/book-store-management-backend/module/user/userstore/list.go b/book-store-management-backend/module/user/userstore/list.go index 1235490..3dacf23 100644 --- a/book-store-management-backend/module/user/userstore/list.go +++ b/book-store-management-backend/module/user/userstore/list.go @@ -27,7 +27,7 @@ func (s *sqlStore) ListUser( if errPaging != nil { return nil, errPaging } - db = dbTemp.Limit(int(paging.Limit)) + db = dbTemp for i := range moreKeys { db = db.Preload(moreKeys[i]) diff --git a/book-store-management-backend/module/user/usertransport/ginuser/login.go b/book-store-management-backend/module/user/usertransport/ginuser/login.go index 836531e..667b627 100755 --- a/book-store-management-backend/module/user/usertransport/ginuser/login.go +++ b/book-store-management-backend/module/user/usertransport/ginuser/login.go @@ -19,7 +19,7 @@ import ( // @Accept json // @Produce json // @Param user body usermodel.ReqLoginUser true "login information" -// @Response 200 {object} common.ResSuccess "status of response" +// @Response 200 {object} usermodel.Account "user token" // @Response 400 {object} common.AppError "error" // @Router /login [post] func Login(appCtx appctx.AppContext) gin.HandlerFunc { @@ -39,23 +39,13 @@ func Login(appCtx appctx.AppContext) gin.HandlerFunc { md5 := hasher.NewMd5Hash() - business := userbiz.NewLoginBiz( - appCtx, repo, - common.MaxAgeAccessToken, common.MaxAgeRefreshToken, - tokenProvider, md5) + business := userbiz.NewLoginBiz(appCtx, repo, 60*60*24*15, 60*60*24*30, tokenProvider, md5) account, err := business.Login(c.Request.Context(), &data) if err != nil { panic(err) } - c.SetCookie( - common.AccessTokenStrInCookie, account.AccessToken.Token, common.MaxAgeAccessToken, - "/", "", true, true) - c.SetCookie( - common.RefreshTokenStrInCookie, account.RefreshToken.Token, common.MaxAgeRefreshToken, - "/", "", true, true) - - c.JSON(http.StatusOK, common.SimpleSuccessResponse(true)) + c.JSON(http.StatusOK, common.SimpleSuccessResponse(account)) } } diff --git a/book-store-management-backend/module/user/usertransport/ginuser/refresh_token.go b/book-store-management-backend/module/user/usertransport/ginuser/refresh_token.go index 68b080a..7c56127 100644 --- a/book-store-management-backend/module/user/usertransport/ginuser/refresh_token.go +++ b/book-store-management-backend/module/user/usertransport/ginuser/refresh_token.go @@ -5,6 +5,7 @@ import ( "book-store-management-backend/component/appctx" "book-store-management-backend/component/tokenprovider/jwt" "book-store-management-backend/module/user/userbiz" + "book-store-management-backend/module/user/usermodel" "github.com/gin-gonic/gin" "net/http" ) @@ -15,26 +16,26 @@ import ( // @Tags auth // @Accept json // @Produce json -// @Response 200 {object} common.ResSuccess "status of response" +// @Param refreshToken body usermodel.ReqRefreshToken true "refreshToken" +// @Response 200 {object} usermodel.AccountWithoutRefresh "user token" // @Response 400 {object} common.AppError "error" // @Router /refreshToken [post] func RefreshToken(appCtx appctx.AppContext) gin.HandlerFunc { return func(c *gin.Context) { - refreshToken := c.MustGet(common.RefreshTokenStr).(string) + var data usermodel.ReqRefreshToken + if err := c.ShouldBind(&data); err != nil { + c.JSON(http.StatusBadRequest, common.ErrInvalidRequest(err)) + } tokenProvider := jwt.NewTokenJWTProvider(appCtx.GetSecretKey()) - business := userbiz.NewRefreshTokenBiz( - appCtx, common.MaxAgeAccessToken, tokenProvider) - account, err := business.RefreshToken(c.Request.Context(), refreshToken) + business := userbiz.NewRefreshTokenBiz(appCtx, 60*60*24*15, tokenProvider) + account, err := business.RefreshToken(c.Request.Context(), &data) + if err != nil { panic(err) } - c.SetCookie( - common.AccessTokenStrInCookie, account.AccessToken.Token, common.MaxAgeAccessToken, - "/", "", true, true) - - c.JSON(http.StatusOK, common.SimpleSuccessResponse(true)) + c.JSON(http.StatusOK, common.SimpleSuccessResponse(account)) } } diff --git a/book-store-management-backend/module/user/usertransport/ginuser/route.go b/book-store-management-backend/module/user/usertransport/ginuser/route.go index 5127a4d..82050bb 100644 --- a/book-store-management-backend/module/user/usertransport/ginuser/route.go +++ b/book-store-management-backend/module/user/usertransport/ginuser/route.go @@ -8,16 +8,12 @@ import ( func SetupRoutes(router *gin.RouterGroup, appCtx appctx.AppContext) { router.POST("/login", Login(appCtx)) - router.POST("/signOut", SignOut(appCtx)) - token := router.Group("", middleware.GetRefreshTokenCookieHandler()) + router.POST("/refreshToken", RefreshToken(appCtx)) + auth := router.Group("", middleware.RequireAuth(appCtx)) { - token.POST("/refreshToken", RefreshToken(appCtx), middleware.GetRefreshTokenCookieHandler()) + auth.GET("/profile", SeeProfile(appCtx), middleware.RequireAuth(appCtx)) } - auth := router.Group("", middleware.GetAccessTokenCookieHandler(), middleware.RequireAuth(appCtx)) - { - auth.GET("/profile", SeeProfile(appCtx)) - } - users := router.Group("/users", middleware.GetAccessTokenCookieHandler(), middleware.RequireAuth(appCtx)) + users := router.Group("/users", middleware.RequireAuth(appCtx)) { users.GET("", ListUser(appCtx)) users.GET("/all", GetAllUser(appCtx)) diff --git a/book-store-management-backend/module/user/usertransport/ginuser/sign_out.go b/book-store-management-backend/module/user/usertransport/ginuser/sign_out.go deleted file mode 100644 index 3b81935..0000000 --- a/book-store-management-backend/module/user/usertransport/ginuser/sign_out.go +++ /dev/null @@ -1,29 +0,0 @@ -package ginuser - -import ( - "book-store-management-backend/common" - "book-store-management-backend/component/appctx" - "github.com/gin-gonic/gin" - "net/http" -) - -// @BasePath /v1 -// @Summary SignOut -// @Tags auth -// @Accept json -// @Produce json -// @Response 200 {object} common.ResSuccess "status of response" -// @Response 400 {object} common.AppError "error" -// @Router /signOut [post] -func SignOut(appCtx appctx.AppContext) gin.HandlerFunc { - return func(c *gin.Context) { - c.SetCookie( - common.AccessTokenStrInCookie, "", -1, - "/", "", true, true) - c.SetCookie( - common.RefreshTokenStrInCookie, "", -1, - "/", "", true, true) - - c.JSON(http.StatusOK, common.SimpleSuccessResponse(true)) - } -} From 5a310c48b9174bd1e2761a163552aa9bdb496ab9 Mon Sep 17 00:00:00 2001 From: NLNM-0-0 Date: Sun, 24 Dec 2023 17:14:38 +0700 Subject: [PATCH 2/2] fix: update database --- sql/13-dump-2023_12_24.sql | 614 ++++++++++++++++++ {sql => sql_dump_save}/12-dump-2023_12_20.sql | 0 2 files changed, 614 insertions(+) create mode 100644 sql/13-dump-2023_12_24.sql rename {sql => sql_dump_save}/12-dump-2023_12_20.sql (100%) diff --git a/sql/13-dump-2023_12_24.sql b/sql/13-dump-2023_12_24.sql new file mode 100644 index 0000000..659e1b2 --- /dev/null +++ b/sql/13-dump-2023_12_24.sql @@ -0,0 +1,614 @@ +-- MySQL dump 10.13 Distrib 8.0.34, for Linux (x86_64) +-- +-- Host: 103.57.221.113 Database: bookstoremanagement +-- ------------------------------------------------------ +-- Server version 8.0.33 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `Author` +-- + +DROP TABLE IF EXISTS `Author`; +CREATE TABLE `Author` ( + `id` varchar(12) NOT NULL, + `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `Book`; +CREATE TABLE `Book` ( + `id` varchar(12) NOT NULL, + `name` varchar(100) NOT NULL, + `booktitleid` varchar(12) NOT NULL, + `publisherid` varchar(12) NOT NULL, + `edition` int NOT NULL DEFAULT '1', + `quantity` int NOT NULL DEFAULT '0', + `listedPrice` int DEFAULT NULL, + `sellPrice` int DEFAULT NULL, + `importPrice` int DEFAULT NULL, + `imgUrl` text, + `createdAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) NOT NULL DEFAULT '1', + PRIMARY KEY (`id`,`booktitleid`), + KEY `Book_BookTitle_id_fk` (`booktitleid`), + KEY `Book_Publisher_id_fk` (`publisherid`), + CONSTRAINT `Book_BookTitle_id_fk` FOREIGN KEY (`booktitleid`) REFERENCES `BookTitle` (`id`), + CONSTRAINT `Book_Publisher_id_fk` FOREIGN KEY (`publisherid`) REFERENCES `Publisher` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `BookTitle`; +CREATE TABLE `BookTitle` ( + `id` varchar(12) NOT NULL, + `name` varchar(100) NOT NULL, + `desc` text, + `authorIds` text NOT NULL, + `categoryIds` text NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) NOT NULL DEFAULT '1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `Category`; +CREATE TABLE `Category` ( + `id` varchar(12) NOT NULL, + `name` varchar(50) NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `Feature`; +CREATE TABLE `Feature` ( + `id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `description` text, + `groupName` text, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `ImportNote`; +CREATE TABLE `ImportNote` ( + `id` varchar(12) NOT NULL, + `supplierId` varchar(12) NOT NULL, + `totalPrice` int DEFAULT '0', + `status` enum('InProgress','Done','Cancel') DEFAULT 'InProgress', + `closedBy` varchar(12) DEFAULT NULL, + `closedAt` datetime DEFAULT NULL, + `createdBy` varchar(12) NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`), + KEY `supplierId` (`supplierId`), + KEY `closedBy` (`closedBy`), + KEY `createdBy` (`createdBy`), + CONSTRAINT `ImportNote_ibfk_1` FOREIGN KEY (`supplierId`) REFERENCES `Supplier` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `ImportNote_ibfk_2` FOREIGN KEY (`closedBy`) REFERENCES `MUser` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `ImportNote_ibfk_3` FOREIGN KEY (`createdBy`) REFERENCES `MUser` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `ImportNoteDetail`; +CREATE TABLE `ImportNoteDetail` ( + `importNoteId` varchar(12) NOT NULL, + `bookId` varchar(12) NOT NULL, + `price` int NOT NULL, + `qtyImport` int DEFAULT '0', + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`importNoteId`,`bookId`), + KEY `bookId` (`bookId`), + CONSTRAINT `ImportNoteDetail_ibfk_1` FOREIGN KEY (`importNoteId`) REFERENCES `ImportNote` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `ImportNoteDetail_ibfk_2` FOREIGN KEY (`bookId`) REFERENCES `Book` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `InventoryCheckNote`; +CREATE TABLE `InventoryCheckNote` ( + `id` varchar(12) NOT NULL, + `qtyDifferent` int NOT NULL, + `qtyAfterAdjust` int NOT NULL, + `createdBy` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`), + KEY `createdBy` (`createdBy`), + CONSTRAINT `InventoryCheckNote_ibfk_1` FOREIGN KEY (`createdBy`) REFERENCES `MUser` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `InventoryCheckNoteDetail`; +CREATE TABLE `InventoryCheckNoteDetail` ( + `inventoryCheckNoteId` varchar(12) NOT NULL, + `bookId` varchar(12) NOT NULL, + `initial` int NOT NULL, + `difference` int NOT NULL, + `final` int NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`inventoryCheckNoteId`,`bookId`), + KEY `bookId` (`bookId`), + CONSTRAINT `InventoryCheckNoteDetail_ibfk_1` FOREIGN KEY (`inventoryCheckNoteId`) REFERENCES `InventoryCheckNote` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `InventoryCheckNoteDetail_ibfk_2` FOREIGN KEY (`bookId`) REFERENCES `Book` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `Invoice`; +CREATE TABLE `Invoice` ( + `id` varchar(13) NOT NULL, + `totalPrice` int NOT NULL, + `createdBy` varchar(13) NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `InvoiceDetail`; +CREATE TABLE `InvoiceDetail` ( + `invoiceId` varchar(13) NOT NULL, + `bookId` varchar(13) NOT NULL, + `bookName` text, + `qty` int NOT NULL, + `unitPrice` int NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`invoiceId`,`bookId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `MUser`; +CREATE TABLE `MUser` ( + `id` varchar(12) NOT NULL, + `name` text NOT NULL, + `phone` varchar(13) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', + `address` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', + `email` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `password` text NOT NULL, + `salt` text NOT NULL, + `roleId` varchar(12) NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `imgUrl` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, + `isActive` tinyint(1) NOT NULL DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`) USING BTREE, + KEY `roleId` (`roleId`), + CONSTRAINT `MUser_ibfk_1` FOREIGN KEY (`roleId`) REFERENCES `Role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `Publisher`; +CREATE TABLE `Publisher` ( + `id` varchar(12) NOT NULL, + `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `Role`; +CREATE TABLE `Role` ( + `id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `RoleFeature`; +CREATE TABLE `RoleFeature` ( + `roleId` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `featureId` varchar(30) NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`roleId`,`featureId`), + KEY `featureId` (`featureId`), + CONSTRAINT `RoleFeature_ibfk_1` FOREIGN KEY (`roleId`) REFERENCES `Role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `RoleFeature_ibfk_2` FOREIGN KEY (`featureId`) REFERENCES `Feature` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `StockChangeHistory`; +CREATE TABLE `StockChangeHistory` ( + `id` varchar(12) NOT NULL, + `bookId` varchar(12) NOT NULL, + `qty` int NOT NULL, + `qtyLeft` int NOT NULL, + `type` enum('Sell','Import','Modify') NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`,`bookId`), + KEY `bookId` (`bookId`), + CONSTRAINT `StockChangeHistory_ibfk_1` FOREIGN KEY (`bookId`) REFERENCES `Book` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `StockReport`; +CREATE TABLE `StockReport` ( + `id` varchar(12) NOT NULL, + `timeFrom` timestamp NOT NULL, + `timeTo` timestamp NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `StockReportDetail`; +CREATE TABLE `StockReportDetail` ( + `reportId` varchar(12) NOT NULL, + `bookId` varchar(12) NOT NULL, + `initial` int NOT NULL, + `sell` int NOT NULL, + `import` int NOT NULL, + `modify` int NOT NULL, + `final` int NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`reportId`,`bookId`), + KEY `bookId` (`bookId`), + CONSTRAINT `StockReportDetail_ibfk_1` FOREIGN KEY (`reportId`) REFERENCES `StockReport` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `StockReportDetail_ibfk_2` FOREIGN KEY (`bookId`) REFERENCES `Book` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `Supplier`; +CREATE TABLE `Supplier` ( + `id` varchar(12) NOT NULL, + `name` text NOT NULL, + `email` text NOT NULL, + `phone` varchar(11) NOT NULL, + `debt` int DEFAULT '0', + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `phone` (`phone`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `SupplierDebt`; +CREATE TABLE `SupplierDebt` ( + `id` varchar(12) NOT NULL, + `supplierId` varchar(12) NOT NULL, + `qty` int NOT NULL, + `qtyLeft` int NOT NULL, + `type` enum('Debt','Pay') NOT NULL, + `createdBy` varchar(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`,`supplierId`), + KEY `createdBy` (`createdBy`), + KEY `supplierId` (`supplierId`), + CONSTRAINT `SupplierDebt_ibfk_1` FOREIGN KEY (`createdBy`) REFERENCES `MUser` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `SupplierDebt_ibfk_2` FOREIGN KEY (`supplierId`) REFERENCES `Supplier` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `SupplierDebtReport`; +CREATE TABLE `SupplierDebtReport` ( + `id` varchar(12) NOT NULL, + `timeFrom` timestamp NOT NULL, + `timeTo` timestamp NOT NULL, + `initial` int NOT NULL, + `debt` int NOT NULL, + `pay` int NOT NULL, + `final` int NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +DROP TABLE IF EXISTS `SupplierDebtReportDetail`; +CREATE TABLE `SupplierDebtReportDetail` ( + `reportId` varchar(12) NOT NULL, + `supplierId` varchar(12) NOT NULL, + `initial` int NOT NULL, + `debt` int NOT NULL, + `pay` int NOT NULL, + `final` int NOT NULL, + `createdAt` datetime DEFAULT CURRENT_TIMESTAMP, + `updatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deletedAt` datetime DEFAULT NULL, + `isActive` tinyint(1) DEFAULT '1', + PRIMARY KEY (`reportId`,`supplierId`), + KEY `supplierId` (`supplierId`), + CONSTRAINT `SupplierDebtReportDetail_ibfk_1` FOREIGN KEY (`supplierId`) REFERENCES `Supplier` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT `SupplierDebtReportDetail_ibfk_2` FOREIGN KEY (`reportId`) REFERENCES `SupplierDebtReport` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `Author` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('tgak', 'Adam Khoo', '2023-12-02 01:51:49', '2023-12-02 01:51:49', NULL, 1); +INSERT INTO `Author` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('tgFFujio', 'Fujiko Fujio', '2023-12-19 01:50:09', '2023-12-19 01:50:09', NULL, 1); +INSERT INTO `Author` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('tghat', 'Hồ Anh Thái', '2023-12-19 00:26:41', '2023-12-19 00:26:41', NULL, 1); +INSERT INTO `Author` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('tgic', 'Iris Cao', '2023-12-19 00:26:41', '2023-12-19 00:26:41', NULL, 1), +('tgnc', 'Nam Cao', '2023-12-19 00:28:00', '2023-12-19 00:28:00', NULL, 1), +('tgnna', 'Nguyễn Nhật Ánh', '2023-12-02 01:51:49', '2023-12-02 01:51:49', NULL, 1), +('tgnnt', 'Nguyễn Ngọc Tư', '2023-12-19 00:28:00', '2023-12-19 00:28:00', NULL, 1), +('tgnpv', 'Nguyễn Phong Việt', '2023-12-19 00:26:41', '2023-12-19 00:26:41', NULL, 1), +('tgntp', 'Nguyễn Thị Phụng', '2023-12-19 02:05:31', '2023-12-19 02:05:31', NULL, 1), +('tgnull', 'Không/chưa tác giả', '2023-12-19 01:41:51', '2023-12-19 01:41:51', NULL, 1), +('tgth', 'Trang Hạ', '2023-12-19 00:26:41', '2023-12-19 00:26:41', NULL, 1), +('tgtn', 'Tuệ Nghi', '2023-12-19 00:26:41', '2023-12-19 00:26:41', NULL, 1), +('tgvef', 'Viktor E Frankl', '2023-12-02 01:51:49', '2023-12-02 01:51:49', NULL, 1), +('tgvtp', 'Vũ Trọng Phụng', '2023-12-19 00:28:00', '2023-12-19 00:28:00', NULL, 1), +('tgynh', 'Yuval Noah Harari', '2023-12-19 02:16:00', '2023-12-19 02:16:00', NULL, 1); + +INSERT INTO `Book` (`id`, `name`, `booktitleid`, `publisherid`, `edition`, `quantity`, `listedPrice`, `sellPrice`, `importPrice`, `imgUrl`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dsslsln', 'Sapiens Lược Sử Loài Người', 'dsslsln', 'nxbls', 1, 5, 299000, 299001, 299000, 'https://cdn0.fahasa.com/media/catalog/product/8/9/8935270703554.jpg', '2023-12-19 02:17:08', '2023-12-19 02:17:45', NULL, 1); +INSERT INTO `Book` (`id`, `name`, `booktitleid`, `publisherid`, `edition`, `quantity`, `listedPrice`, `sellPrice`, `importPrice`, `imgUrl`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('s100ma', '100 Món Ăn Ngày Thường', 'ds100ma', 'nxbtn', 1, 12, 46000, 46000, 46000, 'https://cdn0.fahasa.com/media/catalog/product/1/1/1118020260362_1.jpg', '2023-12-19 02:07:56', '2023-12-19 02:23:21', NULL, 1); +INSERT INTO `Book` (`id`, `name`, `booktitleid`, `publisherid`, `edition`, `quantity`, `listedPrice`, `sellPrice`, `importPrice`, `imgUrl`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('sdoraemont12', 'Doraemon - Tập 12', 'dsdoraemon', 'nxbdk', 1, 29, 30000, 30000, 30000, 'https://momotaro.vn/upload/images/12_50.jpg', '2023-12-19 01:51:57', '2023-12-19 02:09:26', NULL, 1); +INSERT INTO `Book` (`id`, `name`, `booktitleid`, `publisherid`, `edition`, `quantity`, `listedPrice`, `sellPrice`, `importPrice`, `imgUrl`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('sdoraemonv23', 'Doraemon vol23. Nobita và những pháp sư gió bí ẩn', 'dsdoraemon', 'nxbdk', 1, 40, 35000, 35000, 35000, 'https://bizweb.dktcdn.net/thumb/1024x1024/100/299/021/products/8935244814316.jpg?v=1679371436627', '2023-12-19 01:56:51', '2023-12-19 01:57:10', NULL, 1), +('sdtls', 'Đi Tìm Lẽ Sống', 'dsdtls', 'nxbnn', 1, 96, 80000, 80000, 80000, 'https://salt.tikicdn.com/ts/product/80/14/8b/61fb657f347d14d9d7bf6fe901001a8e.jpg', '2023-12-19 01:47:37', '2023-12-19 02:23:21', NULL, 1), +('sgktoan5', 'Sách giáo khoa Toán lớp 5', 'dsgktoan', 'nxbgd', 1, 1000, 18000, 18000, 18000, 'https://hieusach24h.com/wp-content/uploads/2021/09/Toan-5-1.jpg', '2023-12-19 02:12:33', '2023-12-19 02:12:56', NULL, 1), +('sgktoan7', 'Sách giáo khoa Toán lớp 7', 'dsgktoan', 'nxbgd', 1, 1000, 18000, 18000, 18000, 'https://bizweb.dktcdn.net/100/397/635/products/giai-bai-tap-sgk-toan-lop-7-tap-1.png?v=1620215042633', '2023-12-19 02:12:33', '2023-12-19 02:12:56', NULL, 1), +('sipm2', 'Official IELTS Practice Materials 2 with DVD', 'dsipm2', 'nxbgd', 1, 10, 500000, 500000, 500000, 'https://cdn0.fahasa.com/media/catalog/product/i/m/image_195509_1_25616.jpg', '2023-12-19 01:43:25', '2023-12-19 01:43:48', NULL, 1), +('smb', 'Mắt biếc', 'dsmb', 'nxbdk', 1, 20, 85000, 85000, 85000, 'https://salt.tikicdn.com/cache/w1200/ts/product/10/d1/35/b2098bf8884bb8a5fbcd42a978a6b601.jpg', '2023-12-19 01:00:19', '2023-12-19 01:03:23', NULL, 1), +('stlbt', 'Tôi là Bêtô', 'stlbt', 'nxbdk', 1, 95, 100000, 120000, 60000, 'https://www.nxbtre.com.vn/Images/Book/nxbtre_full_05112021_111104.jpg', '2023-12-14 06:31:35', '2023-12-19 00:48:08', NULL, 1), +('sttgbct', 'Tôi tài giỏi, bạn cũng thế!', 'sttgbct', 'nxbtn', 1, 99, 150000, 150000, 150000, 'https://metaisach.com/wp-content/uploads/2019/05/toi-tai-gioi-ban-cung-the.jpg', '2023-12-19 01:35:19', '2023-12-19 02:23:21', NULL, 1); + +INSERT INTO `BookTitle` (`id`, `name`, `desc`, `authorIds`, `categoryIds`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('ds100ma', '100 Món Ăn Ngày Thường', 'Quyển sách 100 Món Ăn Ngày Thường cung cấp cho bạn những công thức nấu ăn món ăn ngày thường thông dụng nhất, dễ thực hiện với những kỹ thuật không quá cao.', 'tgntp', 'dmdna', '2023-12-19 02:06:50', '2023-12-19 02:06:50', NULL, 1); +INSERT INTO `BookTitle` (`id`, `name`, `desc`, `authorIds`, `categoryIds`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dsdoraemon', 'Doraemon', 'Doraemon', 'tgFFujio', 'dmtruyen|dmtn', '2023-12-19 01:50:40', '2023-12-19 01:56:39', NULL, 1); +INSERT INTO `BookTitle` (`id`, `name`, `desc`, `authorIds`, `categoryIds`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dsdtls', 'Đi Tìm Lẽ Sống', 'Cuốn sách giúp người ta tìm được ý nghĩa cuộc sống', 'tgvef', 'dmkns', '2023-12-14 18:44:24', '2023-12-19 00:57:08', NULL, 1); +INSERT INTO `BookTitle` (`id`, `name`, `desc`, `authorIds`, `categoryIds`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dsgktoan', 'SGK Toán', 'Sách giáo khoa toán', 'tgnull', 'dmgd|dmsgk', '2023-12-19 02:11:35', '2023-12-19 02:11:35', NULL, 1), +('dsipm2', 'Official IELTS Practice Materials 2', 'Official IELTS Practice Materials 2', 'tgnull', 'dmtk|dmgd', '2023-12-19 01:41:59', '2023-12-19 01:41:59', NULL, 1), +('dsmb', 'Mắt biếc', 'Mắt biếc là tiểu thuyết của nhà văn Nguyễn Nhật Ánh trong loạt truyện viết về tình yêu thanh thiếu niên của tác giả này cùng với Thằng quỷ nhỏ, Cô gái đến từ hôm qua,...', 'tgnna', 'dmtt|dmtruyen', '2023-12-19 00:59:30', '2023-12-19 00:59:30', NULL, 1), +('dsslsln', 'Sapiens Lược Sử Loài Người', 'Sapiens Lược Sử Loài Người', 'tgynh', 'dmls', '2023-12-19 02:16:07', '2023-12-19 02:16:07', NULL, 1), +('stlbt', 'Tôi là Bêtô', 'Một tác phẩm của Nguyễn Nhật Ánh', 'tgnna', 'dmtt|dmtruyen', '2023-12-09 20:41:28', '2023-12-11 09:54:37', NULL, 1), +('sttgbct', 'Tôi tài giỏi, bạn cũng thế!', 'Tôi tài giỏi, bạn cũng thế! (nhan đề gốc tiếng Anh: I Am Gifted, So Are You!) là quyển sách bán chạy nhất của doanh nhân người Singapore Adam Khoo, viết về những phương pháp học tập tiên tiến. Quyển sách đã được dịch ra hàng chục thứ tiếng, trong đó Tôi tài giỏi, bạn cũng thế! là phiên bản tiếng Việt được dịch bởi hai dịch giả nổi tiếng Trần Đăng Khoa và Uông Xuân Vy của TGM Books. Tại Việt Nam, quyển sách đã trở thành một hiện tượng giáo dục trong những năm 2009-2011 và đạt được nhiều thành tựu trong lĩnh vực xuất bản, tạo ra kỷ lục mới cho ngành xuất bản Việt Nam với hơn 200.000 bản in được bán ra và hơn 400.000 e-book được phân phối.', 'tgak', 'dmkns', '2023-12-10 16:07:24', '2023-12-11 09:50:45', NULL, 1); + +INSERT INTO `Category` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dmdna', 'Dạy nấu ăn', '2023-12-19 00:54:38', '2023-12-19 00:54:38', NULL, 1); +INSERT INTO `Category` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dmgd', 'Giáo dục ', '2023-12-19 01:40:41', '2023-12-19 01:40:41', NULL, 1); +INSERT INTO `Category` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dmkh', 'Khoa học', '2023-12-19 00:54:38', '2023-12-19 00:54:38', NULL, 1); +INSERT INTO `Category` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('dmkns', 'Kỹ năng sống', '2023-12-02 01:52:21', '2023-12-02 01:52:21', NULL, 1), +('dmls', 'Lịch sử', '2023-12-19 00:54:38', '2023-12-19 00:54:38', NULL, 1), +('dmsgk', 'Sách giáo khoa', '2023-12-02 01:52:21', '2023-12-02 01:52:21', NULL, 1), +('dmtch', 'Truyển cảm hứng', '2023-12-19 00:54:38', '2023-12-19 00:54:38', NULL, 1), +('dmtg', 'Tôn giáo', '2023-12-19 00:54:38', '2023-12-19 00:54:38', NULL, 1), +('dmtk', 'Tham khảo', '2023-12-19 01:40:29', '2023-12-19 01:40:29', NULL, 1), +('dmtl', 'Tâm lý', '2023-12-19 00:54:38', '2023-12-19 00:54:38', NULL, 1), +('dmtn', 'Thiếu nhi', '2023-12-19 00:54:38', '2023-12-19 00:54:38', NULL, 1), +('dmtruyen', 'Truyện', '2023-12-02 01:52:21', '2023-12-02 01:52:21', NULL, 1), +('dmtt', 'Tiểu thuyết', '2023-12-02 01:52:21', '2023-12-02 01:52:21', NULL, 1), +('SzG-PmOIg', 'sách nấu ăn', '2023-12-19 02:26:31', '2023-12-19 02:26:31', NULL, 1); + +INSERT INTO `Feature` (`id`, `description`, `groupName`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('AUTHOR_CREATE', 'Tạo tác giả', 'Tác giả', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1); +INSERT INTO `Feature` (`id`, `description`, `groupName`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('AUTHOR_DELETE', 'Xóa tác giả', 'Tác giả', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1); +INSERT INTO `Feature` (`id`, `description`, `groupName`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('AUTHOR_UPDATE', 'Chỉnh sửa thông tin tác giả', 'Tác giả', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1); +INSERT INTO `Feature` (`id`, `description`, `groupName`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('AUTHOR_VIEW', 'Xem tác giả', 'Tác giả', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_CREATE', 'Tạo sách', 'Sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_DELETE', 'Xóa sách', 'Sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_TITLE_CREATE', 'Tạo đầu sách', 'Đầu sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_TITLE_DELETE', 'Xóa đầu sách', 'Đầu sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_TITLE_UPDATE', 'Chỉnh sửa thông tin đầu sách', 'Đầu sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_TITLE_VIEW', 'Xem đầu sách', 'Đầu sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_UPDATE', 'Chỉnh sửa thông tin sách', 'Sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('BOOK_VIEW', 'Xem sách', 'Sách', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('CATEGORY_CREATE', 'Tạo danh mục', 'Danh mục', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('CATEGORY_DELETE', 'Xóa danh mục', 'Danh mục', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('CATEGORY_UPDATE', 'Chỉnh sửa thông tin danh mục', 'Danh mục', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('CATEGORY_VIEW', 'Xem danh mục', 'Danh mục', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('IMPORT_NOTE_CREATE', 'Tạo phiếu nhập', 'Phiếu nhập', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('IMPORT_NOTE_STATUS', 'Chỉnh sửa trạng thái phiếu nhập', 'Phiếu nhập', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('IMPORT_NOTE_VIEW', 'Xem phiếu nhập', 'Phiếu nhập', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('INVENTORY_NOTE_CREATE', 'Tạo phiếu kiểm kho', 'Phiếu kiểm kho', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('INVENTORY_NOTE_VIEW', 'Xem phiếu kiểm kho', 'Phiếu kiểm kho', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('INVOICE_CREATE', 'Bán hàng', 'Hóa đơn', '2023-12-15 01:46:28', '2023-12-15 01:46:28', NULL, 1), +('INVOICE_VIEW', 'Xem hóa đơn', 'Hóa đơn', '2023-12-15 01:46:28', '2023-12-15 01:46:28', NULL, 1), +('PUBLISHER_CREATE', 'Tạo nhà sản xuất', 'Nhà sản xuất', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('PUBLISHER_VIEW', 'Xem nhà sản xuất', 'Nhà sản xuất', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('REPORT_VIEW_SALE', 'Xem báo cáo doanh thu', 'Báo cáo', '2023-12-15 07:34:11', '2023-12-15 07:34:11', NULL, 1), +('REPORT_VIEW_STOCK', 'Xem báo cáo tồn kho', 'Báo cáo', '2023-12-15 07:34:11', '2023-12-15 07:34:11', NULL, 1), +('REPORT_VIEW_SUPPLIER', 'Xem báo cáo nợ', 'Báo cáo', '2023-12-15 07:34:11', '2023-12-15 07:34:11', NULL, 1), +('SUPPLIER_CREATE', 'Tạo nhà cung cấp', 'Nhà cung cấp', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('SUPPLIER_PAY', 'Trả nợ nhà cung cấp', 'Nhà cung cấp', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('SUPPLIER_UPDATE_INFO', 'Chỉnh sửa thông tin nhà cung cấp', 'Nhà cung cấp', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('SUPPLIER_VIEW', 'Xem nhà cung cấp', 'Nhà cung cấp', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('USER_UPDATE_INFO', 'Chỉnh sửa thông tin người dùng', 'Nhân viên', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('USER_UPDATE_STATE', 'Chỉnh sửa trạng thái', 'Nhân viên', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1), +('USER_VIEW', 'Xem người dùng', 'Nhân viên', '2023-12-13 08:54:39', '2023-12-14 07:56:30', NULL, 1); + + + + + + + + + +INSERT INTO `Invoice` (`id`, `totalPrice`, `createdBy`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('oVFpPmOSR', 482000, 'g3W21A7SR', '2023-12-19 02:23:21', '2023-12-19 02:23:21', NULL, 1); +INSERT INTO `Invoice` (`id`, `totalPrice`, `createdBy`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('Wzu-YiOIR', 156000, 'g3W21A7SR', '2023-12-19 02:09:26', '2023-12-19 02:09:26', NULL, 1); + + +INSERT INTO `InvoiceDetail` (`invoiceId`, `bookId`, `bookName`, `qty`, `unitPrice`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('oVFpPmOSR', 's100ma', '100 Món Ăn Ngày Thường', 2, 46000, '2023-12-19 02:23:21', '2023-12-19 02:23:21', NULL, 1); +INSERT INTO `InvoiceDetail` (`invoiceId`, `bookId`, `bookName`, `qty`, `unitPrice`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('oVFpPmOSR', 'sdtls', 'Đi Tìm Lẽ Sống', 3, 80000, '2023-12-19 02:23:21', '2023-12-19 02:23:21', NULL, 1); +INSERT INTO `InvoiceDetail` (`invoiceId`, `bookId`, `bookName`, `qty`, `unitPrice`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('oVFpPmOSR', 'sttgbct', 'Tôi tài giỏi, bạn cũng thế!', 1, 150000, '2023-12-19 02:23:21', '2023-12-19 02:23:21', NULL, 1); +INSERT INTO `InvoiceDetail` (`invoiceId`, `bookId`, `bookName`, `qty`, `unitPrice`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('Wzu-YiOIR', 's100ma', '100 Món Ăn Ngày Thường', 1, 46000, '2023-12-19 02:09:26', '2023-12-19 02:09:26', NULL, 1), +('Wzu-YiOIR', 'sdoraemont12', 'Doraemon - Tập 12', 1, 30000, '2023-12-19 02:09:26', '2023-12-19 02:09:26', NULL, 1), +('Wzu-YiOIR', 'sdtls', 'Đi Tìm Lẽ Sống', 1, 80000, '2023-12-19 02:09:26', '2023-12-19 02:09:26', NULL, 1); + +INSERT INTO `MUser` (`id`, `name`, `phone`, `address`, `email`, `password`, `salt`, `roleId`, `createdAt`, `updatedAt`, `deletedAt`, `imgUrl`, `isActive`) VALUES +('bgIqwQSIg', 'user', '', '', 'user@gmail.com', '0dd71ba5a82e98ccdc6f5edb6fb870a5', 'ByVwWucjSGZkozLFeQcopssBrHPbCHoqRuUCFUbpfIhhqGUujj', 'user', '2023-12-02 01:52:32', '2023-12-24 09:56:50', NULL, 'https://cdn-icons-png.flaticon.com/512/149/149071.png', 1); +INSERT INTO `MUser` (`id`, `name`, `phone`, `address`, `email`, `password`, `salt`, `roleId`, `createdAt`, `updatedAt`, `deletedAt`, `imgUrl`, `isActive`) VALUES +('g3W21A7SR', 'admin', '1234567890', '', 'admin@gmail.com', '5e107317df151f6e8e0015c4f2ee7936', 'mVMxRDAHpAJfyzuiXWRELghNpynUqBKueSboGBcrwHUuzEWsms', 'admin', '2023-12-02 01:52:32', '2023-12-24 09:56:50', NULL, 'https://cdn-icons-png.flaticon.com/512/149/149071.png', 1); +INSERT INTO `MUser` (`id`, `name`, `phone`, `address`, `email`, `password`, `salt`, `roleId`, `createdAt`, `updatedAt`, `deletedAt`, `imgUrl`, `isActive`) VALUES +('kJ68EidIg', 'Thu Nguyen', '0987654321', 'None', 'nguyenkimanhthu25092003@gmail.com', 'd06c7bc74ad018e3ade1fdd536b1ec96', 'AXUGqeiDINLbHeaGmxKauptFKnwJgOUxZaMGaCBuJncsphurtf', 'user', '2023-12-19 02:29:43', '2023-12-24 09:56:50', NULL, 'https://cdn-icons-png.flaticon.com/512/149/149071.png', 1); + +INSERT INTO `Publisher` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('nxbdk', 'Kim Đồng', '2023-12-02 01:52:21', '2023-12-02 01:52:21', NULL, 1); +INSERT INTO `Publisher` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('nxbgd', 'Giáo dục', '2023-12-02 01:52:21', '2023-12-10 16:07:18', NULL, 1); +INSERT INTO `Publisher` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('nxbld', 'Lao động', '2023-12-19 00:23:52', '2023-12-19 00:23:52', NULL, 1); +INSERT INTO `Publisher` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('nxbls', 'Lịch sử', '2023-12-19 02:17:06', '2023-12-20 18:12:07', NULL, 1), +('nxbnn', 'Nhã Nam', '2023-12-19 00:23:52', '2023-12-19 00:23:52', NULL, 1), +('nxbpn', 'Tri thức', '2023-12-19 00:23:52', '2023-12-19 00:23:52', NULL, 1), +('nxbtn', 'Thanh niên', '2023-12-19 00:23:52', '2023-12-19 00:23:52', NULL, 1), +('nxbtre', 'Trẻ', '2023-12-19 00:23:52', '2023-12-19 00:23:52', NULL, 1); + +INSERT INTO `Role` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('admin', 'admin', '2023-12-02 01:52:40', '2023-12-17 12:49:31', NULL, 1); +INSERT INTO `Role` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('user', 'user', '2023-12-02 01:52:40', '2023-12-02 01:52:40', NULL, 1); +INSERT INTO `Role` (`id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('WEyQEidSg', 'thu ngân', '2023-12-19 02:30:07', '2023-12-19 02:30:23', NULL, 1); + +INSERT INTO `RoleFeature` (`roleId`, `featureId`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('admin', 'AUTHOR_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1); +INSERT INTO `RoleFeature` (`roleId`, `featureId`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('admin', 'AUTHOR_DELETE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1); +INSERT INTO `RoleFeature` (`roleId`, `featureId`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('admin', 'AUTHOR_UPDATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1); +INSERT INTO `RoleFeature` (`roleId`, `featureId`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('admin', 'AUTHOR_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_DELETE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_TITLE_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_TITLE_DELETE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_TITLE_UPDATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_TITLE_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_UPDATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'BOOK_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'CATEGORY_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'CATEGORY_DELETE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'CATEGORY_UPDATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'CATEGORY_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'IMPORT_NOTE_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'IMPORT_NOTE_STATUS', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'IMPORT_NOTE_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'INVENTORY_NOTE_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'INVENTORY_NOTE_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'INVOICE_CREATE', '2023-12-15 01:47:00', '2023-12-15 01:47:00', NULL, 1), +('admin', 'INVOICE_VIEW', '2023-12-15 01:47:00', '2023-12-15 01:47:00', NULL, 1), +('admin', 'PUBLISHER_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'PUBLISHER_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'REPORT_VIEW_SALE', '2023-12-15 07:34:53', '2023-12-15 07:34:53', NULL, 1), +('admin', 'REPORT_VIEW_STOCK', '2023-12-15 07:34:53', '2023-12-15 07:34:53', NULL, 1), +('admin', 'REPORT_VIEW_SUPPLIER', '2023-12-15 07:34:53', '2023-12-15 07:34:53', NULL, 1), +('admin', 'SUPPLIER_CREATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'SUPPLIER_PAY', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'SUPPLIER_UPDATE_INFO', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'SUPPLIER_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'USER_UPDATE_INFO', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'USER_UPDATE_STATE', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('admin', 'USER_VIEW', '2023-12-12 08:46:33', '2023-12-12 08:46:33', NULL, 1), +('user', 'AUTHOR_CREATE', '2023-12-12 08:48:06', '2023-12-12 08:48:06', NULL, 1), +('WEyQEidSg', 'AUTHOR_CREATE', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1), +('WEyQEidSg', 'AUTHOR_DELETE', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1), +('WEyQEidSg', 'AUTHOR_UPDATE', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1), +('WEyQEidSg', 'AUTHOR_VIEW', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1), +('WEyQEidSg', 'CATEGORY_CREATE', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1), +('WEyQEidSg', 'CATEGORY_DELETE', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1), +('WEyQEidSg', 'CATEGORY_UPDATE', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1), +('WEyQEidSg', 'CATEGORY_VIEW', '2023-12-19 02:30:07', '2023-12-19 02:30:07', NULL, 1); + + + + + + + +INSERT INTO `Supplier` (`id`, `name`, `email`, `phone`, `debt`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('ncc1980', '1980 Book', '1980books@gmail.com', '0345689012', 0, '2023-12-19 01:09:49', '2023-12-19 02:28:19', NULL, 1); +INSERT INTO `Supplier` (`id`, `name`, `email`, `phone`, `debt`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('nccapb', 'Alpha Books', 'alphabooks@gmail.com', '0123456784', 0, '2023-12-19 01:08:18', '2023-12-19 01:08:18', NULL, 1); +INSERT INTO `Supplier` (`id`, `name`, `email`, `phone`, `debt`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('nccfn', 'First News', 'firstnews@gmail.com', '0123456785', 0, '2023-12-19 01:08:18', '2023-12-19 01:08:18', NULL, 1); +INSERT INTO `Supplier` (`id`, `name`, `email`, `phone`, `debt`, `createdAt`, `updatedAt`, `deletedAt`, `isActive`) VALUES +('ncchnb', 'Hanoi Books', 'hanoibooks@gmail.com', '0123456782', 0, '2023-12-19 01:06:25', '2023-12-19 01:06:25', NULL, 1), +('ncchtt', 'Hoa học trò', 'hoahoctro@gmail.com', '0123456788', 0, '2023-12-19 01:10:28', '2023-12-19 01:10:28', NULL, 1), +('ncckd', 'Kim Đồng', 'kimdong@gmail.com', '0123456781', 0, '2023-12-19 01:06:25', '2023-12-19 01:06:25', NULL, 1), +('nccnn', 'Nhã Nam', 'nhanam@gmail.com', '0123456780', 0, '2023-12-19 01:05:13', '2023-12-19 01:05:13', NULL, 1), +('nccpdb', 'PandaBooks', 'pandabooks@gmail.com', '0123456783', 0, '2023-12-19 01:08:18', '2023-12-19 01:08:18', NULL, 1), +('nccttt', 'Tri Thức Trẻ', 'trithuctre@gmail.com', '0123456786', 0, '2023-12-19 01:09:49', '2023-12-19 01:09:49', NULL, 1); + +DELIMITER // +CREATE TRIGGER update_closedAt +BEFORE UPDATE ON ImportNote +FOR EACH ROW +BEGIN + IF NEW.status != 'InProgress' THEN + SET NEW.closedAt = CURRENT_TIMESTAMP; + END IF; +END; +// +DELIMITER ; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + diff --git a/sql/12-dump-2023_12_20.sql b/sql_dump_save/12-dump-2023_12_20.sql similarity index 100% rename from sql/12-dump-2023_12_20.sql rename to sql_dump_save/12-dump-2023_12_20.sql