forked from b00tc4mp/isdi-parttime-202403
-
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.
create doc app and api folders; install mongoose & vite; start with r…
…egister; b00tc4mp#160
- Loading branch information
unknown
authored and
unknown
committed
Jul 30, 2024
1 parent
eb33273
commit a181b82
Showing
939 changed files
with
189,487 additions
and
81 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
class ContentError extends Error { | ||
constructor(message) { | ||
super(message) | ||
|
||
this.name = this.constructor.name | ||
} | ||
} | ||
|
||
|
||
|
||
class MatchError extends Error { | ||
constructor(message) { | ||
super(message) | ||
|
||
this.name = this.constructor.name | ||
} | ||
} | ||
|
||
|
||
|
||
class DuplicityError extends Error { | ||
constructor(message) { | ||
super(message) | ||
|
||
this.name = this.constructor.name | ||
} | ||
} | ||
|
||
|
||
class SystemError extends Error { | ||
constructor(message) { | ||
super(message) | ||
|
||
this.name = this.constructor.name | ||
} | ||
} | ||
|
||
|
||
class CredentialsError extends Error { | ||
constructor(message) { | ||
super(message) | ||
|
||
this.name = this.constructor.name | ||
} | ||
} | ||
|
||
class NotFoundError extends Error { | ||
constructor(message) { | ||
super(message) | ||
|
||
this.name = this.constructor.name | ||
} | ||
} | ||
|
||
export { | ||
ContentError, | ||
MatchError, | ||
DuplicityError, | ||
SystemError, | ||
CredentialsError, | ||
NotFoundError | ||
} | ||
|
||
const errors = { | ||
ContentError, | ||
MatchError, | ||
DuplicityError, | ||
SystemError, | ||
CredentialsError, | ||
NotFoundError | ||
} | ||
|
||
export default errors |
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 @@ | ||
{ | ||
"name": "com", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
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,75 @@ | ||
import { ContentError, MatchError } from "./errors.js" | ||
|
||
const NAME_REGEX = /^[a-zA-Z=\[\]\{\}\<\>\(\)]{1,}$/ | ||
const USERNAME_REGEX = /^[\w-]+$/ | ||
const PASSWORD_REGEX = /^[\w-$%&=\[\]\{\}\<\>\(\)]{8,}$/ | ||
const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
const ID_REGEX = /^[0-9a-z]+$/ | ||
|
||
function validateName(name, explain = 'name') { | ||
if (typeof name !== 'string' || !NAME_REGEX.test(name)) | ||
throw new ContentError(`${explain} name is not valid`) | ||
} | ||
|
||
function validateSurname(surname, explain = 'surname') { | ||
if (typeof surname !== 'string' || !NAME_REGEX.test(surname)) | ||
throw new ContentError(`${explain} is not valid`) | ||
} | ||
|
||
function validateUserName(username, explain = 'username') { | ||
if (typeof username !== 'string' || !USERNAME_REGEX.test(username)) | ||
throw new ContentError(`${explain} is not valid`) | ||
} | ||
|
||
function validatePassword(password) { | ||
if (typeof password !== 'string' || !PASSWORD_REGEX.test(password)) | ||
throw new ContentError('password is not valid') | ||
} | ||
|
||
function validatePasswordMatch(password, passwordRepeat) { | ||
if (password !== passwordRepeat) { | ||
throw new MatchError('password don\'t match') | ||
} | ||
} | ||
|
||
function validateCallback(callback) { | ||
if (typeof callback !== 'function') | ||
throw new TypeError('callback is not a function') | ||
} | ||
|
||
function validateEmail(email) { | ||
if (typeof email !== 'string' || !EMAIL_REGEX.test(email)) | ||
throw new ContentError('email is not valid') | ||
} | ||
|
||
function validateText(text, explain = 'text', maxLength = Infinity) { | ||
if (typeof text !== 'string' || !text.length || text.length > maxLength) { | ||
throw new ContentError(`${explain} is not valid`) | ||
} | ||
} | ||
|
||
function validateURL(url, explain = 'url') { | ||
if (typeof url !== 'string' || !url.startsWith('http')) { | ||
throw new ContentError(`${explain} is not valid`) | ||
} | ||
} | ||
|
||
function validateId(id, explain = 'id') { | ||
if (!ID_REGEX.test(id) || typeof id !== 'string') | ||
throw new ContentError(`${explain} is not valid`) | ||
} | ||
|
||
const validate = { | ||
name: validateName, | ||
surname: validateSurname, | ||
username: validateUserName, | ||
password: validatePassword, | ||
passwordMatch: validatePasswordMatch, | ||
callback: validateCallback, | ||
email: validateEmail, | ||
text: validateText, | ||
url: validateURL, | ||
id: validateId | ||
} | ||
|
||
export default validate |
Oops, something went wrong.