mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
2
.gitignore
vendored
2
.gitignore
vendored
@@ -28,6 +28,7 @@ yarn-error.log*
|
||||
# local env files
|
||||
.env*.local
|
||||
.env
|
||||
.env*.production
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
@@ -44,3 +45,4 @@ public/uploads
|
||||
|
||||
# vscode
|
||||
.vscode
|
||||
|
||||
|
||||
13
.prettierrc
13
.prettierrc
@@ -1,7 +1,14 @@
|
||||
{
|
||||
"semi": true,
|
||||
"trailingComma": "all",
|
||||
"singleQuote": true,
|
||||
"arrowParens": "always",
|
||||
"bracketSpacing": true,
|
||||
"jsxSingleQuote": false,
|
||||
"printWidth": 90,
|
||||
"proseWrap": "always",
|
||||
"quoteProps": "as-needed",
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "all",
|
||||
"useTabs": false,
|
||||
"plugins": ["prettier-plugin-jsdoc"]
|
||||
}
|
||||
|
||||
551
LICENSE.md
551
LICENSE.md
@@ -1,27 +1,61 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted
|
||||
to copy and distribute verbatim copies of this license document, but changing it is not
|
||||
allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of
|
||||
works.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||
The licenses for most software and other practical works are designed to take away your
|
||||
freedom to share and change the works. By contrast, the GNU General Public License is
|
||||
intended to guarantee your freedom to share and change all versions of a program--to make
|
||||
sure it remains free software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to any other work
|
||||
released this way by its authors. You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public
|
||||
Licenses are designed to make sure that you have the freedom to distribute copies of free
|
||||
software (and charge for them if you wish), that you receive source code or can get it if
|
||||
you want it, that you can change the software or use pieces of it in new free programs,
|
||||
and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking
|
||||
you to surrender the rights. Therefore, you have certain responsibilities if you
|
||||
distribute copies of the software, or if you modify it: responsibilities to respect the
|
||||
freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you
|
||||
must pass on to the recipients the same freedoms that you received. You must make sure
|
||||
that they, too, receive or can get the source code. And you must show them these terms so
|
||||
they know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright
|
||||
on the software, and (2) offer you this License giving you legal permission to copy,
|
||||
distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no
|
||||
warranty for this free software. For both users' and authors' sake, the GPL requires that
|
||||
modified versions be marked as changed, so that their problems will not be attributed
|
||||
erroneously to authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||
Some devices are designed to deny users access to install or run modified versions of the
|
||||
software inside them, although the manufacturer can do so. This is fundamentally
|
||||
incompatible with the aim of protecting users' freedom to change the software. The
|
||||
systematic pattern of such abuse occurs in the area of products for individuals to use,
|
||||
which is precisely where it is most unacceptable. Therefore, we have designed this version
|
||||
of the GPL to prohibit the practice for those products. If such problems arise
|
||||
substantially in other domains, we stand ready to extend this provision to those domains
|
||||
in future versions of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||
Finally, every program is threatened constantly by software patents. States should not
|
||||
allow patents to restrict development and use of software on general-purpose computers,
|
||||
but in those that do, we wish to avoid the special danger that patents applied to a free
|
||||
program could make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
@@ -31,64 +65,120 @@ The precise terms and conditions for copying, distribution and modification foll
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of works, such as
|
||||
semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||
"The Program" refers to any copyrightable work licensed under this License. Each licensee
|
||||
is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||
To "modify" a work means to copy from or adapt all or part of the work in a fashion
|
||||
requiring copyright permission, other than the making of an exact copy. The resulting work
|
||||
is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
To "propagate" a work means to do anything with it that, without permission, would make
|
||||
you directly or secondarily liable for infringement under applicable copyright law, except
|
||||
executing it on a computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the public, and in some
|
||||
countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
To "convey" a work means any kind of propagation that enables other parties to make or
|
||||
receive copies. Mere interaction with a user through a computer network, with no transfer
|
||||
of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
An interactive user interface displays "Appropriate Legal Notices" to the extent that it
|
||||
includes a convenient and prominently visible feature that (1) displays an appropriate
|
||||
copyright notice, and (2) tells the user that there is no warranty for the work (except to
|
||||
the extent that warranties are provided), that licensees may convey the work under this
|
||||
License, and how to view a copy of this License. If the interface presents a list of user
|
||||
commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||
The "source code" for a work means the preferred form of the work for making modifications
|
||||
to it. "Object code" means any non-source form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
A "Standard Interface" means an interface that either is an official standard defined by a
|
||||
recognized standards body, or, in the case of interfaces specified for a particular
|
||||
programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
The "System Libraries" of an executable work include anything, other than the work as a
|
||||
whole, that (a) is included in the normal form of packaging a Major Component, but which
|
||||
is not part of that Major Component, and (b) serves only to enable use of the work with
|
||||
that Major Component, or to implement a Standard Interface for which an implementation is
|
||||
available to the public in source code form. A "Major Component", in this context, means a
|
||||
major essential component (kernel, window system, and so on) of the specific operating
|
||||
system (if any) on which the executable work runs, or a compiler used to produce the work,
|
||||
or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
The "Corresponding Source" for a work in object code form means all the source code needed
|
||||
to generate, install, and (for an executable work) run the object code and to modify the
|
||||
work, including scripts to control those activities. However, it does not include the
|
||||
work's System Libraries, or general-purpose tools or generally available free programs
|
||||
which are used unmodified in performing those activities but which are not part of the
|
||||
work. For example, Corresponding Source includes interface definition files associated
|
||||
with source files for the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require, such as by intimate
|
||||
data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
The Corresponding Source need not include anything that users can regenerate automatically
|
||||
from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
All rights granted under this License are granted for the term of copyright on the
|
||||
Program, and are irrevocable provided the stated conditions are met. This License
|
||||
explicitly affirms your unlimited permission to run the unmodified Program. The output
|
||||
from running a covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your rights of fair use or
|
||||
other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
You may make, run and propagate covered works that you do not convey, without conditions
|
||||
so long as your license otherwise remains in force. You may convey covered works to others
|
||||
for the sole purpose of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with the terms of this
|
||||
License in conveying all material for which you do not control copyright. Those thus
|
||||
making or running the covered works for you must do so exclusively on your behalf, under
|
||||
your direction and control, on terms that prohibit them from making any copies of your
|
||||
copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated
|
||||
below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
No covered work shall be deemed part of an effective technological measure under any
|
||||
applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
|
||||
adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of
|
||||
such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of
|
||||
technological measures to the extent such circumvention is effected by exercising rights
|
||||
under this License with respect to the covered work, and you disclaim any intention to
|
||||
limit operation or modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of technological
|
||||
measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any
|
||||
medium, provided that you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice; keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code; keep intact all
|
||||
notices of the absence of any warranty; and give all recipients a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
You may charge any price or no price for each copy that you convey, and you may offer
|
||||
support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
You may convey a work based on the Program, or the modifications to produce it from the
|
||||
Program, in the form of source code under the terms of section 4, provided that you also
|
||||
meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
@@ -98,11 +188,19 @@ You may convey a work based on the Program, or the modifications to produce it f
|
||||
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
A compilation of a covered work with other separate and independent works, which are not
|
||||
by their nature extensions of the covered work, and which are not combined with it such as
|
||||
to form a larger program, in or on a volume of a storage or distribution medium, is called
|
||||
an "aggregate" if the compilation and its resulting copyright are not used to limit the
|
||||
access or legal rights of the compilation's users beyond what the individual works permit.
|
||||
Inclusion of a covered work in an aggregate does not cause this License to apply to the
|
||||
other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5,
|
||||
provided that you also convey the machine-readable Corresponding Source under the terms of
|
||||
this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
@@ -114,49 +212,67 @@ You may convey a covered work in object code form under the terms of sections 4
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and corresponding source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
A separable portion of the object code, whose source code is excluded from the
|
||||
Corresponding Source as a System Library, need not be included in conveying the object
|
||||
code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
A "User Product" is either (1) a "consumer product", which means any tangible personal
|
||||
property which is normally used for personal, family, or household purposes, or (2)
|
||||
anything designed or sold for incorporation into a dwelling. In determining whether a
|
||||
product is a consumer product, doubtful cases shall be resolved in favor of coverage. For
|
||||
a particular product received by a particular user, "normally used" refers to a typical or
|
||||
common use of that class of product, regardless of the status of the particular user or of
|
||||
the way in which the particular user actually uses, or expects or is expected to use, the
|
||||
product. A product is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent the only
|
||||
significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
"Installation Information" for a User Product means any methods, procedures, authorization
|
||||
keys, or other information required to install and execute modified versions of a covered
|
||||
work in that User Product from a modified version of its Corresponding Source. The
|
||||
information must suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
If you convey an object code work under this section in, or with, or specifically for use
|
||||
in, a User Product, and the conveying occurs as part of a transaction in which the right
|
||||
of possession and use of the User Product is transferred to the recipient in perpetuity or
|
||||
for a fixed term (regardless of how the transaction is characterized), the Corresponding
|
||||
Source conveyed under this section must be accompanied by the Installation Information.
|
||||
But this requirement does not apply if neither you nor any third party retains the ability
|
||||
to install modified object code on the User Product (for example, the work has been
|
||||
installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
The requirement to provide Installation Information does not include a requirement to
|
||||
continue to provide support service, warranty, or updates for a work that has been
|
||||
modified or installed by the recipient, or for the User Product in which it has been
|
||||
modified or installed. Access to a network may be denied when the modification itself
|
||||
materially and adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this
|
||||
section must be in a format that is publicly documented (and with an implementation
|
||||
available to the public in source code form), and must require no special password or key
|
||||
for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
"Additional permissions" are terms that supplement the terms of this License by making
|
||||
exceptions from one or more of its conditions. Additional permissions that are applicable
|
||||
to the entire Program shall be treated as though they were included in this License, to
|
||||
the extent that they are valid under applicable law. If additional permissions apply only
|
||||
to part of the Program, that part may be used separately under those permissions, but the
|
||||
entire Program remains governed by this License without regard to the additional
|
||||
permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
When you convey a copy of a covered work, you may at your option remove any additional
|
||||
permissions from that copy, or from any part of it. (Additional permissions may be written
|
||||
to require their own removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work, for which you have or
|
||||
can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
Notwithstanding any other provision of this License, for material you add to a covered
|
||||
work, you may (if authorized by the copyright holders of that material) supplement the
|
||||
terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
@@ -181,199 +297,198 @@ that material) supplement the terms of this License with terms:
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
All other non-permissive additional terms are considered "further restrictions" within the
|
||||
meaning of section 10. If the Program as you received it, or any part of it, contains a
|
||||
notice stating that it is governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains a further
|
||||
restriction but permits relicensing or conveying under this License, you may add to a
|
||||
covered work material governed by the terms of that license document, provided that the
|
||||
further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
If you add terms to a covered work in accord with this section, you must place, in the
|
||||
relevant source files, a statement of the additional terms that apply to those files, or a
|
||||
notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately
|
||||
written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
You may not propagate or modify a covered work except as expressly provided under this
|
||||
License. Any attempt otherwise to propagate or modify it is void, and will automatically
|
||||
terminate your rights under this License (including any patent licenses granted under the
|
||||
third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
However, if you cease all violation of this License, then your license from a particular
|
||||
copyright holder is reinstated (a) provisionally, unless and until the copyright holder
|
||||
explicitly and finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means prior to 60 days
|
||||
after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the
|
||||
copyright holder notifies you of the violation by some reasonable means, this is the first
|
||||
time you have received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after your receipt of the
|
||||
notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
Termination of your rights under this section does not terminate the licenses of parties
|
||||
who have received copies or rights from you under this License. If your rights have been
|
||||
terminated and not permanently reinstated, you do not qualify to receive new licenses for
|
||||
the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
You are not required to accept this License in order to receive or run a copy of the
|
||||
Program. Ancillary propagation of a covered work occurring solely as a consequence of
|
||||
using peer-to-peer transmission to receive a copy likewise does not require acceptance.
|
||||
However, nothing other than this License grants you permission to propagate or modify any
|
||||
covered work. These actions infringe copyright if you do not accept this License.
|
||||
Therefore, by modifying or propagating a covered work, you indicate your acceptance of
|
||||
this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
Each time you convey a covered work, the recipient automatically receives a license from
|
||||
the original licensors, to run, modify and propagate that work, subject to this License.
|
||||
You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
An "entity transaction" is a transaction transferring control of an organization, or
|
||||
substantially all assets of one, or subdividing an organization, or merging organizations.
|
||||
If propagation of a covered work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever licenses to the work
|
||||
the party's predecessor in interest had or could give under the previous paragraph, plus a
|
||||
right to possession of the Corresponding Source of the work from the predecessor in
|
||||
interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
You may not impose any further restrictions on the exercise of the rights granted or
|
||||
affirmed under this License. For example, you may not impose a license fee, royalty, or
|
||||
other charge for exercise of rights granted under this License, and you may not initiate
|
||||
litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent
|
||||
claim is infringed by making, using, selling, offering for sale, or importing the Program
|
||||
or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
A "contributor" is a copyright holder who authorizes use under this License of the Program
|
||||
or a work on which the Program is based. The work thus licensed is called the
|
||||
contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
A contributor's "essential patent claims" are all patent claims owned or controlled by the
|
||||
contributor, whether already acquired or hereafter acquired, that would be infringed by
|
||||
some manner, permitted by this License, of making, using, or selling its contributor
|
||||
version, but do not include claims that would be infringed only as a consequence of
|
||||
further modification of the contributor version. For purposes of this definition,
|
||||
"control" includes the right to grant patent sublicenses in a manner consistent with the
|
||||
requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under
|
||||
the contributor's essential patent claims, to make, use, sell, offer for sale, import and
|
||||
otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
In the following three paragraphs, a "patent license" is any express agreement or
|
||||
commitment, however denominated, not to enforce a patent (such as an express permission to
|
||||
practice a patent or covenant not to sue for patent infringement). To "grant" such a
|
||||
patent license to a party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding
|
||||
Source of the work is not available for anyone to copy, free of charge and under the terms
|
||||
of this License, through a publicly available network server or other readily accessible
|
||||
means, then you must either (1) cause the Corresponding Source to be so available, or (2)
|
||||
arrange to deprive yourself of the benefit of the patent license for this particular work,
|
||||
or (3) arrange, in a manner consistent with the requirements of this License, to extend
|
||||
the patent license to downstream recipients. "Knowingly relying" means you have actual
|
||||
knowledge that, but for the patent license, your conveying the covered work in a country,
|
||||
or your recipient's use of the covered work in a country, would infringe one or more
|
||||
identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or
|
||||
propagate by procuring conveyance of, a covered work, and grant a patent license to some
|
||||
of the parties receiving the covered work authorizing them to use, propagate, modify or
|
||||
convey a specific copy of the covered work, then the patent license you grant is
|
||||
automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
A patent license is "discriminatory" if it does not include within the scope of its
|
||||
coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more
|
||||
of the rights that are specifically granted under this License. You may not convey a
|
||||
covered work if you are a party to an arrangement with a third party that is in the
|
||||
business of distributing software, under which you make payment to the third party based
|
||||
on the extent of your activity of conveying the work, and under which the third party
|
||||
grants, to any of the parties who would receive the covered work from you, a
|
||||
discriminatory patent license (a) in connection with copies of the covered work conveyed
|
||||
by you (or copies made from those copies), or (b) primarily for and in connection with
|
||||
specific products or compilations that contain the covered work, unless you entered into
|
||||
that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or
|
||||
other defenses to infringement that may otherwise be available to you under applicable
|
||||
patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that
|
||||
contradict the conditions of this License, they do not excuse you from the conditions of
|
||||
this License. If you cannot convey a covered work so as to satisfy simultaneously your
|
||||
obligations under this License and any other pertinent obligations, then as a consequence
|
||||
you may not convey it at all. For example, if you agree to terms that obligate you to
|
||||
collect a royalty for further conveying from those to whom you convey the Program, the
|
||||
only way you could satisfy both those terms and this License would be to refrain entirely
|
||||
from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
Notwithstanding any other provision of this License, you have permission to link or
|
||||
combine any covered work with a work licensed under version 3 of the GNU Affero General
|
||||
Public License into a single combined work, and to convey the resulting work. The terms of
|
||||
this License will continue to apply to the part which is the covered work, but the special
|
||||
requirements of the GNU Affero General Public License, section 13, concerning interaction
|
||||
through a network will apply to the combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General
|
||||
Public License from time to time. Such new versions will be similar in spirit to the
|
||||
present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
Each version is given a distinguishing version number. If the Program specifies that a
|
||||
certain numbered version of the GNU General Public License "or any later version" applies
|
||||
to it, you have the option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software Foundation. If the Program
|
||||
does not specify a version number of the GNU General Public License, you may choose any
|
||||
version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General
|
||||
Public License can be used, that proxy's public statement of acceptance of a version
|
||||
permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
Later license versions may give you additional or different permissions. However, no
|
||||
additional obligations are imposed on any author or copyright holder as a result of your
|
||||
choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
|
||||
WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
|
||||
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
|
||||
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
|
||||
SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR
|
||||
OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
|
||||
HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE
|
||||
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
|
||||
DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
|
||||
HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given
|
||||
local legal effect according to their terms, reviewing courts shall apply local law that
|
||||
most closely approximates an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a copy of the Program in
|
||||
return for a fee.
|
||||
|
||||
96
README.md
96
README.md
@@ -2,47 +2,65 @@
|
||||
|
||||
## About
|
||||
|
||||
The Biergarten App is a web application designed for beer lovers to share their favorite brews and breweries with like-minded people online.
|
||||
The Biergarten App is a web application designed for beer lovers to share their favorite
|
||||
brews and breweries with like-minded people online.
|
||||
|
||||
This application's stack consists of Next.js, Prisma and Vercel Postgres. I'm motivated to learn more about these technologies while exploring my passion for beer.
|
||||
This application's stack consists of Next.js, Prisma and Vercel Postgres. I'm motivated to
|
||||
learn more about these technologies while exploring my passion for beer.
|
||||
|
||||
I've also incorporated different APIs into the application, such as the Cloudinary API for image uploading, the SparkPost API for email services as well as Mapbox for geolocation and map data.
|
||||
I've also incorporated different APIs into the application, such as the Cloudinary API for
|
||||
image uploading, the SparkPost API for email services as well as Mapbox for geolocation
|
||||
and map data.
|
||||
|
||||
To handle serverless functions (API routes), I use the next-connect package.
|
||||
|
||||
On the client-side, I use Tailwind CSS, Headless UI and Daisy UI for styling to create a visually appealing and user-friendly interface.
|
||||
On the client-side, I use Tailwind CSS, Headless UI and Daisy UI for styling to create a
|
||||
visually appealing and user-friendly interface.
|
||||
|
||||
I'm sharing my code publicly so that others can learn from it and use it as a reference for their own projects.
|
||||
I'm sharing my code publicly so that others can learn from it and use it as a reference
|
||||
for their own projects.
|
||||
|
||||
### Some beer terminology
|
||||
|
||||
In this app you will encounter various beer related terms. Here is a list of terms used in this app and their definitions.
|
||||
In this app you will encounter various beer related terms. Here is a list of terms used in
|
||||
this app and their definitions.
|
||||
|
||||
#### ABV
|
||||
|
||||
[Alcohol by volume](https://en.wikipedia.org/wiki/Alcohol_by_volume) (abbreviated as ABV) is a standard measure of how much alcohol (ethanol) is contained in a given volume of an alcoholic beverage (expressed as a volume percent).
|
||||
[Alcohol by volume](https://en.wikipedia.org/wiki/Alcohol_by_volume) (abbreviated as ABV)
|
||||
is a standard measure of how much alcohol (ethanol) is contained in a given volume of an
|
||||
alcoholic beverage (expressed as a volume percent).
|
||||
|
||||
#### IBU
|
||||
|
||||
The [International Bitterness Units](https://en.wikipedia.org/wiki/Beer_measurement#Bitterness) scale, or IBU, is used to approximately quantify the bitterness of beer. This scale is not measured on the perceived bitterness of the beer, but rather the amount of a component of beer known as iso-alpha acids.
|
||||
The
|
||||
[International Bitterness Units](https://en.wikipedia.org/wiki/Beer_measurement#Bitterness)
|
||||
scale, or IBU, is used to approximately quantify the bitterness of beer. This scale is not
|
||||
measured on the perceived bitterness of the beer, but rather the amount of a component of
|
||||
beer known as iso-alpha acids.
|
||||
|
||||
## Technologies
|
||||
|
||||
### General
|
||||
|
||||
- [Next.js](https://nextjs.org/)
|
||||
- A React based framework for building web applications offering several features such as server side rendering, static site generation and API routes.
|
||||
- A React based framework for building web applications offering several features such
|
||||
as server side rendering, static site generation and API routes.
|
||||
|
||||
### Client
|
||||
|
||||
- [SWR](https://swr.vercel.app/)
|
||||
- A React Hooks library for fetching data with support for caching, revalidation and error handling.
|
||||
- A React Hooks library for fetching data with support for caching, revalidation and
|
||||
error handling.
|
||||
- [Tailwind CSS](https://tailwindcss.com/)
|
||||
- A popular open-source utility-first CSS framework that provides pre-defined classes to style HTML elements.
|
||||
- A popular open-source utility-first CSS framework that provides pre-defined classes to
|
||||
style HTML elements.
|
||||
- [Headless UI](https://headlessui.dev/)
|
||||
- A set of completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
|
||||
- A set of completely unstyled, fully accessible UI components, designed to integrate
|
||||
beautifully with Tailwind CSS.
|
||||
- [Daisy UI](https://daisyui.com/)
|
||||
- A component library for Tailwind CSS that provides ready-to-use components for building user interfaces.
|
||||
- A component library for Tailwind CSS that provides ready-to-use components for
|
||||
building user interfaces.
|
||||
|
||||
### Server
|
||||
|
||||
@@ -51,11 +69,14 @@ The [International Bitterness Units](https://en.wikipedia.org/wiki/Beer_measurem
|
||||
- [Vercel Postgres](https://vercel.com/dashboard/stores)
|
||||
- A managed PostgreSQL database service provided by Vercel.
|
||||
- [Cloudinary](https://cloudinary.com/)
|
||||
- A cloud-based image and video management service that provides developers with an easy way to upload, store, and manipulate media assets.
|
||||
- A cloud-based image and video management service that provides developers with an easy
|
||||
way to upload, store, and manipulate media assets.
|
||||
- [SparkPost](https://www.sparkpost.com/)
|
||||
- A cloud-based email delivery service that provides developers with an easy way to send transactional and marketing emails.
|
||||
- A cloud-based email delivery service that provides developers with an easy way to send
|
||||
transactional and marketing emails.
|
||||
- [Mapbox](https://www.mapbox.com/)
|
||||
- A suite of open-source mapping tools that allows developers to add custom maps, search, and navigation into their applications.
|
||||
- A suite of open-source mapping tools that allows developers to add custom maps,
|
||||
search, and navigation into their applications.
|
||||
- [next-connect](https://github.com/hoangvvo/next-connect#readme)
|
||||
- A promise-based method routing and middleware layer for Next.js.
|
||||
|
||||
@@ -63,7 +84,8 @@ The [International Bitterness Units](https://en.wikipedia.org/wiki/Beer_measurem
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Before you can run this application locally, you will need to have the following installed on your machine:
|
||||
Before you can run this application locally, you will need to have the following installed
|
||||
on your machine:
|
||||
|
||||
- [Node.js](https://nodejs.org/en/)
|
||||
- [npm (version 8 or higher)](https://www.npmjs.com/get-npm)
|
||||
@@ -90,7 +112,9 @@ cd the-biergarten-app
|
||||
npm install
|
||||
```
|
||||
|
||||
3. Run the following script to create a `.env` file in the root directory of the project and add the following environment variables. Update these variables with your own values.
|
||||
3. Run the following script to create a `.env` file in the root directory of the project
|
||||
and add the following environment variables. Update these variables with your own
|
||||
values.
|
||||
|
||||
```bash
|
||||
echo "BASE_URL=
|
||||
@@ -118,10 +142,13 @@ SPARKPOST_SENDER_ADDRESS=" > .env
|
||||
### Explanation of environment variables
|
||||
|
||||
- `BASE_URL` is the base URL of the application.
|
||||
- For example, if you are running the application locally, you can set this to `http://localhost:3000`.
|
||||
- `CLOUDINARY_CLOUD_NAME`, `CLOUDINARY_KEY`, and `CLOUDINARY_SECRET` are the credentials for your Cloudinary account.
|
||||
- For example, if you are running the application locally, you can set this to
|
||||
`http://localhost:3000`.
|
||||
- `CLOUDINARY_CLOUD_NAME`, `CLOUDINARY_KEY`, and `CLOUDINARY_SECRET` are the credentials
|
||||
for your Cloudinary account.
|
||||
- You can create a free account [here](https://cloudinary.com/users/register/free).
|
||||
- `CONFIRMATION_TOKEN_SECRET` is the secret used to sign the confirmation token used for email confirmation.
|
||||
- `CONFIRMATION_TOKEN_SECRET` is the secret used to sign the confirmation token used for
|
||||
email confirmation.
|
||||
- You can generate a random string using the`openssl rand -base64 127` command.
|
||||
- `SESSION_SECRET` is the secret used to sign the session cookie.
|
||||
- Use the same command as above to generate a random string.
|
||||
@@ -129,11 +156,15 @@ SPARKPOST_SENDER_ADDRESS=" > .env
|
||||
- You can set this to `biergarten`.
|
||||
- `SESSION_MAX_AGE` is the maximum age of the session cookie in milliseconds.
|
||||
- You can set this to `604800000` (1 week).
|
||||
- `POSTGRES_URL`, `POSTGRES_PRISMA_URL`, `POSTGRES_URL_NON_POOLING`, `POSTGRES_USER`, `POSTGRES_HOST`, `POSTGRES_PASSWORD`, and `POSTGRES_DATABASE` are the credentials for your Vercel Postgres database.
|
||||
- `POSTGRES_URL`, `POSTGRES_PRISMA_URL`, `POSTGRES_URL_NON_POOLING`, `POSTGRES_USER`,
|
||||
`POSTGRES_HOST`, `POSTGRES_PASSWORD`, and `POSTGRES_DATABASE` are the credentials for
|
||||
your Vercel Postgres database.
|
||||
- You can create a free account [here](https://vercel.com/dashboard/stores).
|
||||
- `MAPBOX_ACCESS_TOKEN` and `NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN` are the access tokens for your Mapbox account.
|
||||
- `MAPBOX_ACCESS_TOKEN` and `NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN` are the access tokens for
|
||||
your Mapbox account.
|
||||
- You can create a free account [here](https://account.mapbox.com/auth/signup/).
|
||||
- You will need to create two access tokens, one for the server-side and one for the client-side.
|
||||
- You will need to create two access tokens, one for the server-side and one for the
|
||||
client-side.
|
||||
- `NODE_ENV` is the environment in which the application is running.
|
||||
- You can set this to `development` or `production`.
|
||||
- `SPARKPOST_API_KEY` is the API key for your SparkPost account.
|
||||
@@ -161,12 +192,19 @@ npm run dev
|
||||
|
||||
## License
|
||||
|
||||
The Biergarten App is licensed under the GNU General Public License v3.0. This means that anyone is free to use, modify, and distribute the code as long as they also distribute their modifications under the same license.
|
||||
The Biergarten App is licensed under the GNU General Public License v3.0. This means that
|
||||
anyone is free to use, modify, and distribute the code as long as they also distribute
|
||||
their modifications under the same license.
|
||||
|
||||
I encourage anyone who uses this code for educational purposes to attribute me as the original author, and to provide a link to this repository.
|
||||
I encourage anyone who uses this code for educational purposes to attribute me as the
|
||||
original author, and to provide a link to this repository.
|
||||
|
||||
By contributing to this repository, you agree to license your contributions under the same license as the project.
|
||||
By contributing to this repository, you agree to license your contributions under the same
|
||||
license as the project.
|
||||
|
||||
If you have any questions or concerns about the license, please feel free to submit an issue to this repository.
|
||||
If you have any questions or concerns about the license, please feel free to submit an
|
||||
issue to this repository.
|
||||
|
||||
I hope that this project will be useful to other developers and beer enthusiasts who are interested in learning about web development with Next.js, Prisma, Postgres, and other technologies.
|
||||
I hope that this project will be useful to other developers and beer enthusiasts who are
|
||||
interested in learning about web development with Next.js, Prisma, Postgres, and other
|
||||
technologies.
|
||||
|
||||
2715
package-lock.json
generated
2715
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
59
package.json
59
package.json
@@ -12,42 +12,42 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@hapi/iron": "^7.0.1",
|
||||
"@headlessui/react": "^1.7.13",
|
||||
"@headlessui/tailwindcss": "^0.1.2",
|
||||
"@hookform/resolvers": "^3.0.0",
|
||||
"@mapbox/mapbox-sdk": "^0.15.0",
|
||||
"@headlessui/react": "^1.7.14",
|
||||
"@headlessui/tailwindcss": "^0.1.3",
|
||||
"@hookform/resolvers": "^3.1.0",
|
||||
"@mapbox/mapbox-sdk": "^0.15.1",
|
||||
"@prisma/client": "^4.13.0",
|
||||
"@react-email/components": "^0.0.4",
|
||||
"@react-email/render": "^0.0.6",
|
||||
"@react-email/tailwind": "^0.0.7",
|
||||
"@react-email/components": "^0.0.6",
|
||||
"@react-email/render": "^0.0.7",
|
||||
"@react-email/tailwind": "^0.0.8",
|
||||
"@vercel/analytics": "^1.0.0",
|
||||
"argon2": "^0.30.3",
|
||||
"cloudinary": "^1.35.0",
|
||||
"cloudinary": "^1.36.4",
|
||||
"cookie": "^0.5.0",
|
||||
"date-fns": "^2.29.3",
|
||||
"date-fns": "^2.30.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mapbox-gl": "^2.14.1",
|
||||
"multer": "^2.0.0-rc.4",
|
||||
"multer-storage-cloudinary": "^4.0.0",
|
||||
"next": "^13.2.4",
|
||||
"next": "^13.3.4",
|
||||
"next-connect": "^1.0.0-next.3",
|
||||
"passport": "^0.6.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"pino": "^8.11.0",
|
||||
"pino": "^8.12.0",
|
||||
"pino-pretty": "^10.0.0",
|
||||
"react": "^18.2.0",
|
||||
"react-daisyui": "^3.1.1",
|
||||
"react-daisyui": "^3.1.2",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-email": "^1.9.0",
|
||||
"react-email": "^1.9.3",
|
||||
"react-hook-form": "^7.43.9",
|
||||
"react-icons": "^4.8.0",
|
||||
"react-intersection-observer": "^9.4.3",
|
||||
"react-map-gl": "^7.0.23",
|
||||
"react-responsive-carousel": "^3.2.23",
|
||||
"sparkpost": "^2.1.4",
|
||||
"swr": "^2.1.2",
|
||||
"swr": "^2.1.5",
|
||||
"theme-change": "^2.5.0",
|
||||
"zod": "^3.21.4"
|
||||
},
|
||||
@@ -55,36 +55,37 @@
|
||||
"@faker-js/faker": "^7.6.0",
|
||||
"@types/cookie": "^0.5.1",
|
||||
"@types/ejs": "^3.1.2",
|
||||
"@types/jsonwebtoken": "^9.0.1",
|
||||
"@types/lodash": "^4.14.192",
|
||||
"@types/jsonwebtoken": "^9.0.2",
|
||||
"@types/lodash": "^4.14.194",
|
||||
"@types/mapbox__mapbox-sdk": "^0.13.4",
|
||||
"@types/multer": "^1.4.7",
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/node": "^18.16.3",
|
||||
"@types/passport-local": "^1.0.35",
|
||||
"@types/react": "^18.0.33",
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"@types/react": "^18.2.0",
|
||||
"@types/react-dom": "^18.2.1",
|
||||
"@types/sparkpost": "^2.1.5",
|
||||
"@vercel/fetch": "^6.2.0",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"daisyui": "^2.51.5",
|
||||
"dotenv-cli": "^7.1.0",
|
||||
"eslint": "^8.37.0",
|
||||
"daisyui": "^2.51.6",
|
||||
"dotenv-cli": "^7.2.1",
|
||||
"eslint": "^8.39.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-airbnb-typescript": "17.0.0",
|
||||
"eslint-config-next": "^13.2.4",
|
||||
"eslint-config-next": "^13.3.4",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"postcss": "^8.4.21",
|
||||
"prettier": "^2.8.7",
|
||||
"postcss": "^8.4.23",
|
||||
"prettier": "^2.8.8",
|
||||
"prettier-plugin-jsdoc": "^0.4.2",
|
||||
"prettier-plugin-tailwindcss": "^0.2.6",
|
||||
"prettier-plugin-tailwindcss": "^0.2.8",
|
||||
"prisma": "^4.13.0",
|
||||
"tailwindcss": "^3.3.1",
|
||||
"tailwindcss": "^3.3.2",
|
||||
"tailwindcss-animate": "^1.0.5",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.0.3"
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"prisma": {
|
||||
"schema": "./src/prisma/schema.prisma"
|
||||
"schema": "./src/prisma/schema.prisma",
|
||||
"seed": "npm run seed"
|
||||
}
|
||||
}
|
||||
|
||||
47
src/components/BeerBreweryComments/CommentCardBody.tsx
Normal file
47
src/components/BeerBreweryComments/CommentCardBody.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import useBeerPostComments from '@/hooks/data-fetching/beer-comments/useBeerPostComments';
|
||||
import CommentQueryResult from '@/services/types/CommentSchema/CommentQueryResult';
|
||||
import { FC, useState } from 'react';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
import { z } from 'zod';
|
||||
import CreateCommentValidationSchema from '@/services/types/CommentSchema/CreateCommentValidationSchema';
|
||||
import CommentContentBody from './CommentContentBody';
|
||||
import EditCommentBody from './EditCommentBody';
|
||||
|
||||
interface CommentCardProps {
|
||||
comment: z.infer<typeof CommentQueryResult>;
|
||||
mutate: ReturnType<typeof useBeerPostComments>['mutate'];
|
||||
ref?: ReturnType<typeof useInView>['ref'];
|
||||
handleDeleteRequest: (id: string) => Promise<void>;
|
||||
handleEditRequest: (
|
||||
id: string,
|
||||
data: z.infer<typeof CreateCommentValidationSchema>,
|
||||
) => Promise<void>;
|
||||
}
|
||||
|
||||
const CommentCardBody: FC<CommentCardProps> = ({
|
||||
comment,
|
||||
mutate,
|
||||
ref,
|
||||
handleDeleteRequest,
|
||||
handleEditRequest,
|
||||
}) => {
|
||||
const [inEditMode, setInEditMode] = useState(false);
|
||||
|
||||
return (
|
||||
<div ref={ref}>
|
||||
{!inEditMode ? (
|
||||
<CommentContentBody comment={comment} setInEditMode={setInEditMode} />
|
||||
) : (
|
||||
<EditCommentBody
|
||||
comment={comment}
|
||||
mutate={mutate}
|
||||
setInEditMode={setInEditMode}
|
||||
handleDeleteRequest={handleDeleteRequest}
|
||||
handleEditRequest={handleEditRequest}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CommentCardBody;
|
||||
@@ -36,7 +36,14 @@ const CommentCardDropdown: FC<CommentCardDropdownProps> = ({
|
||||
Edit
|
||||
</button>
|
||||
) : (
|
||||
<button>Report</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
alert('This feature is not yet implemented.');
|
||||
}}
|
||||
>
|
||||
Report
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
</ul>
|
||||
@@ -1,29 +1,24 @@
|
||||
import UserContext from '@/contexts/userContext';
|
||||
import useTimeDistance from '@/hooks/useTimeDistance';
|
||||
import useTimeDistance from '@/hooks/utilities/useTimeDistance';
|
||||
import { format } from 'date-fns';
|
||||
import { Dispatch, FC, SetStateAction, useContext } from 'react';
|
||||
import { Link, Rating } from 'react-daisyui';
|
||||
import CommentQueryResult from '@/services/types/CommentSchema/CommentQueryResult';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
|
||||
import { z } from 'zod';
|
||||
import CommentCardDropdown from './CommentCardDropdown';
|
||||
|
||||
interface CommentContentBodyProps {
|
||||
comment: z.infer<typeof CommentQueryResult>;
|
||||
ref: ReturnType<typeof useInView>['ref'] | undefined;
|
||||
setInEditMode: Dispatch<SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
const CommentContentBody: FC<CommentContentBodyProps> = ({
|
||||
comment,
|
||||
ref,
|
||||
setInEditMode,
|
||||
}) => {
|
||||
const CommentContentBody: FC<CommentContentBodyProps> = ({ comment, setInEditMode }) => {
|
||||
const { user } = useContext(UserContext);
|
||||
const timeDistance = useTimeDistance(new Date(comment.createdAt));
|
||||
|
||||
return (
|
||||
<div className="card-body animate-in fade-in-10" ref={ref}>
|
||||
<div className="card-body animate-in fade-in-10">
|
||||
<div className="flex flex-row justify-between">
|
||||
<div>
|
||||
<h3 className="font-semibold sm:text-2xl">
|
||||
@@ -1,38 +1,44 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { FC, useState, useEffect, Dispatch, SetStateAction } from 'react';
|
||||
import { FC, useState, Dispatch, SetStateAction } from 'react';
|
||||
import { Rating } from 'react-daisyui';
|
||||
import { useForm, SubmitHandler } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
import useBeerPostComments from '@/hooks/useBeerPostComments';
|
||||
import useBeerPostComments from '@/hooks/data-fetching/beer-comments/useBeerPostComments';
|
||||
import CommentQueryResult from '@/services/types/CommentSchema/CommentQueryResult';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
import CreateCommentValidationSchema from '@/services/types/CommentSchema/CreateCommentValidationSchema';
|
||||
import useBreweryPostComments from '@/hooks/data-fetching/brewery-comments/useBreweryPostComments';
|
||||
import FormError from '../ui/forms/FormError';
|
||||
import FormInfo from '../ui/forms/FormInfo';
|
||||
import FormLabel from '../ui/forms/FormLabel';
|
||||
import FormSegment from '../ui/forms/FormSegment';
|
||||
import FormTextArea from '../ui/forms/FormTextArea';
|
||||
|
||||
interface CommentCardDropdownProps {
|
||||
interface EditCommentBodyProps {
|
||||
comment: z.infer<typeof CommentQueryResult>;
|
||||
setInEditMode: Dispatch<SetStateAction<boolean>>;
|
||||
ref: ReturnType<typeof useInView>['ref'] | undefined;
|
||||
mutate: ReturnType<typeof useBeerPostComments>['mutate'];
|
||||
|
||||
mutate: ReturnType<
|
||||
typeof useBeerPostComments | typeof useBreweryPostComments
|
||||
>['mutate'];
|
||||
handleDeleteRequest: (id: string) => Promise<void>;
|
||||
handleEditRequest: (
|
||||
id: string,
|
||||
data: z.infer<typeof CreateCommentValidationSchema>,
|
||||
) => Promise<void>;
|
||||
}
|
||||
|
||||
const EditCommentBody: FC<CommentCardDropdownProps> = ({
|
||||
const EditCommentBody: FC<EditCommentBodyProps> = ({
|
||||
comment,
|
||||
setInEditMode,
|
||||
ref,
|
||||
|
||||
mutate,
|
||||
handleDeleteRequest,
|
||||
handleEditRequest,
|
||||
}) => {
|
||||
const { register, handleSubmit, formState, setValue, watch } = useForm<
|
||||
z.infer<typeof CreateCommentValidationSchema>
|
||||
>({
|
||||
defaultValues: {
|
||||
content: comment.content,
|
||||
rating: comment.rating,
|
||||
},
|
||||
defaultValues: { content: comment.content, rating: comment.rating },
|
||||
resolver: zodResolver(CreateCommentValidationSchema),
|
||||
});
|
||||
|
||||
@@ -40,49 +46,24 @@ const EditCommentBody: FC<CommentCardDropdownProps> = ({
|
||||
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
setIsDeleting(false);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleDelete = async () => {
|
||||
const onDelete = async () => {
|
||||
setIsDeleting(true);
|
||||
const response = await fetch(`/api/beer-comments/${comment.id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete comment');
|
||||
}
|
||||
|
||||
await handleDeleteRequest(comment.id);
|
||||
await mutate();
|
||||
};
|
||||
|
||||
const onSubmit: SubmitHandler<z.infer<typeof CreateCommentValidationSchema>> = async (
|
||||
const onEdit: SubmitHandler<z.infer<typeof CreateCommentValidationSchema>> = async (
|
||||
data,
|
||||
) => {
|
||||
const response = await fetch(`/api/beer-comments/${comment.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: data.content,
|
||||
rating: data.rating,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update comment');
|
||||
}
|
||||
|
||||
setInEditMode(true);
|
||||
await handleEditRequest(comment.id, data);
|
||||
await mutate();
|
||||
setInEditMode(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="card-body animate-in fade-in-10" ref={ref}>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-3">
|
||||
<div className="card-body animate-in fade-in-10">
|
||||
<form onSubmit={handleSubmit(onEdit)} className="space-y-3">
|
||||
<div>
|
||||
<FormInfo>
|
||||
<FormLabel htmlFor="content">Edit your comment</FormLabel>
|
||||
@@ -142,7 +123,7 @@ const EditCommentBody: FC<CommentCardDropdownProps> = ({
|
||||
<button
|
||||
type="button"
|
||||
className="btn-xs btn lg:btn-sm"
|
||||
onClick={handleDelete}
|
||||
onClick={onDelete}
|
||||
disabled={isDeleting || formState.isSubmitting}
|
||||
>
|
||||
Delete
|
||||
@@ -7,7 +7,7 @@ import { FunctionComponent } from 'react';
|
||||
import { useForm, SubmitHandler } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
|
||||
import useBeerPostComments from '@/hooks/useBeerPostComments';
|
||||
import useBeerPostComments from '@/hooks/data-fetching/beer-comments/useBeerPostComments';
|
||||
import CreateCommentValidationSchema from '@/services/types/CommentSchema/CreateCommentValidationSchema';
|
||||
import CommentForm from '../ui/CommentForm';
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import UserContext from '@/contexts/userContext';
|
||||
import { FaRegEdit } from 'react-icons/fa';
|
||||
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
import { z } from 'zod';
|
||||
import useGetBeerPostLikeCount from '@/hooks/useBeerPostLikeCount';
|
||||
import useTimeDistance from '@/hooks/useTimeDistance';
|
||||
import useGetBeerPostLikeCount from '@/hooks/data-fetching/beer-likes/useBeerPostLikeCount';
|
||||
import useTimeDistance from '@/hooks/utilities/useTimeDistance';
|
||||
import BeerPostLikeButton from './BeerPostLikeButton';
|
||||
|
||||
interface BeerInfoHeaderProps {
|
||||
@@ -86,7 +86,8 @@ const BeerInfoHeader: FC<BeerInfoHeaderProps> = ({ beerPost }) => {
|
||||
<div>
|
||||
{(!!likeCount || likeCount === 0) && (
|
||||
<span>
|
||||
Liked by {likeCount} user{likeCount !== 1 && 's'}
|
||||
Liked by {likeCount}
|
||||
{likeCount !== 1 ? ' users' : ' user'}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@ import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult'
|
||||
|
||||
import { FC, MutableRefObject, useContext, useRef } from 'react';
|
||||
import { z } from 'zod';
|
||||
import useBeerPostComments from '@/hooks/useBeerPostComments';
|
||||
import useBeerPostComments from '@/hooks/data-fetching/beer-comments/useBeerPostComments';
|
||||
import { useRouter } from 'next/router';
|
||||
import BeerCommentForm from './BeerCommentForm';
|
||||
|
||||
@@ -18,18 +18,42 @@ interface BeerPostCommentsSectionProps {
|
||||
const BeerPostCommentsSection: FC<BeerPostCommentsSectionProps> = ({ beerPost }) => {
|
||||
const { user } = useContext(UserContext);
|
||||
const router = useRouter();
|
||||
const { id } = beerPost;
|
||||
|
||||
const pageNum = parseInt(router.query.comments_page as string, 10) || 1;
|
||||
const PAGE_SIZE = 4;
|
||||
|
||||
const { comments, isLoading, mutate, setSize, size, isLoadingMore, isAtEnd } =
|
||||
useBeerPostComments({
|
||||
id,
|
||||
id: beerPost.id,
|
||||
pageNum,
|
||||
pageSize: PAGE_SIZE,
|
||||
});
|
||||
|
||||
const commentSectionRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
|
||||
|
||||
async function handleDeleteRequest(id: string) {
|
||||
const response = await fetch(`/api/beer-comments/${id}`, { method: 'DELETE' });
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete comment.');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEditRequest(
|
||||
id: string,
|
||||
data: { content: string; rating: number },
|
||||
) {
|
||||
const response = await fetch(`/api/beer-comments/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ content: data.content, rating: data.rating }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update comment.');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full space-y-3" ref={commentSectionRef}>
|
||||
<div className="card bg-base-300">
|
||||
@@ -63,6 +87,8 @@ const BeerPostCommentsSection: FC<BeerPostCommentsSectionProps> = ({ beerPost })
|
||||
setSize={setSize}
|
||||
size={size}
|
||||
mutate={mutate}
|
||||
handleDeleteRequest={handleDeleteRequest}
|
||||
handleEditRequest={handleEditRequest}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import useCheckIfUserLikesBeerPost from '@/hooks/useCheckIfUserLikesBeerPost';
|
||||
import useCheckIfUserLikesBeerPost from '@/hooks/data-fetching/beer-likes/useCheckIfUserLikesBeerPost';
|
||||
import sendBeerPostLikeRequest from '@/requests/sendBeerPostLikeRequest';
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
|
||||
import useGetBeerPostLikeCount from '@/hooks/useBeerPostLikeCount';
|
||||
import useGetBeerPostLikeCount from '@/hooks/data-fetching/beer-likes/useBeerPostLikeCount';
|
||||
import LikeButton from '../ui/LikeButton';
|
||||
|
||||
const BeerPostLikeButton: FC<{
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import useBeerPostComments from '@/hooks/useBeerPostComments';
|
||||
import CommentQueryResult from '@/services/types/CommentSchema/CommentQueryResult';
|
||||
import { FC, useState } from 'react';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
import { z } from 'zod';
|
||||
import CommentContentBody from './CommentContentBody';
|
||||
import EditCommentBody from './EditCommentBody';
|
||||
|
||||
interface CommentCardProps {
|
||||
comment: z.infer<typeof CommentQueryResult>;
|
||||
mutate: ReturnType<typeof useBeerPostComments>['mutate'];
|
||||
ref?: ReturnType<typeof useInView>['ref'];
|
||||
}
|
||||
|
||||
const CommentCardBody: FC<CommentCardProps> = ({ comment, mutate, ref }) => {
|
||||
const [inEditMode, setInEditMode] = useState(false);
|
||||
|
||||
return !inEditMode ? (
|
||||
<CommentContentBody comment={comment} ref={ref} setInEditMode={setInEditMode} />
|
||||
) : (
|
||||
<EditCommentBody
|
||||
comment={comment}
|
||||
mutate={mutate}
|
||||
setInEditMode={setInEditMode}
|
||||
ref={ref}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default CommentCardBody;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { FC } from 'react';
|
||||
import Spinner from '../ui/Spinner';
|
||||
import CommentLoadingCardBody from './CommentLoadingCardBody';
|
||||
import CommentLoadingCardBody from '../BeerBreweryComments/CommentLoadingCardBody';
|
||||
|
||||
interface LoadingComponentProps {
|
||||
length: number;
|
||||
|
||||
@@ -4,7 +4,7 @@ import Image from 'next/image';
|
||||
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
import { z } from 'zod';
|
||||
import UserContext from '@/contexts/userContext';
|
||||
import useGetBeerPostLikeCount from '@/hooks/useBeerPostLikeCount';
|
||||
import useGetBeerPostLikeCount from '@/hooks/data-fetching/beer-likes/useBeerPostLikeCount';
|
||||
import BeerPostLikeButton from '../BeerById/BeerPostLikeButton';
|
||||
|
||||
const BeerCard: FC<{ post: z.infer<typeof beerPostQueryResult> }> = ({ post }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import UseBeerPostsByBrewery from '@/hooks/useBeerPostsByBrewery';
|
||||
import UseBeerPostsByBrewery from '@/hooks/data-fetching/beer-posts/useBeerPostsByBrewery';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
import Link from 'next/link';
|
||||
import { FC } from 'react';
|
||||
|
||||
@@ -2,12 +2,13 @@ import UserContext from '@/contexts/userContext';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
import { FC, MutableRefObject, useContext, useRef } from 'react';
|
||||
import { z } from 'zod';
|
||||
import useBreweryPostComments from '@/hooks/useBreweryPostComments';
|
||||
import CreateCommentValidationSchema from '@/services/types/CommentSchema/CreateCommentValidationSchema';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm, SubmitHandler } from 'react-hook-form';
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import CommentQueryResult from '@/services/types/CommentSchema/CommentQueryResult';
|
||||
|
||||
import useBreweryPostComments from '@/hooks/data-fetching/brewery-comments/useBreweryPostComments';
|
||||
import LoadingComponent from '../BeerById/LoadingComponent';
|
||||
import CommentsComponent from '../ui/CommentsComponent';
|
||||
import CommentForm from '../ui/CommentForm';
|
||||
@@ -103,6 +104,31 @@ const BreweryCommentsSection: FC<BreweryBeerSectionProps> = ({ breweryPost }) =>
|
||||
|
||||
const commentSectionRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
|
||||
|
||||
const handleDeleteRequest = async (commentId: string) => {
|
||||
const response = await fetch(`/api/brewery-comments/${commentId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
};
|
||||
|
||||
const handleEditRequest = async (
|
||||
commentId: string,
|
||||
data: z.infer<typeof CreateCommentValidationSchema>,
|
||||
) => {
|
||||
const response = await fetch(`/api/brewery-comments/${commentId}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ content: data.content, rating: data.rating }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full space-y-3" ref={commentSectionRef}>
|
||||
<div className="card">
|
||||
@@ -135,6 +161,8 @@ const BreweryCommentsSection: FC<BreweryBeerSectionProps> = ({ breweryPost }) =>
|
||||
size={size}
|
||||
commentSectionRef={commentSectionRef}
|
||||
mutate={mutate}
|
||||
handleDeleteRequest={handleDeleteRequest}
|
||||
handleEditRequest={handleEditRequest}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import UserContext from '@/contexts/userContext';
|
||||
import useGetBreweryPostLikeCount from '@/hooks/useGetBreweryPostLikeCount';
|
||||
import useTimeDistance from '@/hooks/useTimeDistance';
|
||||
import useGetBreweryPostLikeCount from '@/hooks/data-fetching/brewery-likes/useGetBreweryPostLikeCount';
|
||||
import useTimeDistance from '@/hooks/utilities/useTimeDistance';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
import { format } from 'date-fns';
|
||||
import { FC, useContext } from 'react';
|
||||
@@ -72,7 +72,7 @@ const BreweryInfoHeader: FC<BreweryInfoHeaderProps> = ({ breweryPost }) => {
|
||||
<div>
|
||||
{(!!likeCount || likeCount === 0) && (
|
||||
<span>
|
||||
Liked by {likeCount} user{likeCount !== 1 && 's'}
|
||||
Liked by {likeCount} {likeCount === 1 ? 'user' : 'users'}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import useMediaQuery from '@/hooks/useMediaQuery';
|
||||
import useMediaQuery from '@/hooks/utilities/useMediaQuery';
|
||||
import 'mapbox-gl/dist/mapbox-gl.css';
|
||||
import { FC, useMemo } from 'react';
|
||||
import Map, { Marker } from 'react-map-gl';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import UserContext from '@/contexts/userContext';
|
||||
import useGetBreweryPostLikeCount from '@/hooks/useGetBreweryPostLikeCount';
|
||||
import useGetBreweryPostLikeCount from '@/hooks/data-fetching/brewery-likes/useGetBreweryPostLikeCount';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
import { FC, useContext } from 'react';
|
||||
import Link from 'next/link';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import useCheckIfUserLikesBreweryPost from '@/hooks/useCheckIfUserLikesBreweryPost';
|
||||
import useGetBreweryPostLikeCount from '@/hooks/useGetBreweryPostLikeCount';
|
||||
import useCheckIfUserLikesBreweryPost from '@/hooks/data-fetching/brewery-likes/useCheckIfUserLikesBreweryPost';
|
||||
import useGetBreweryPostLikeCount from '@/hooks/data-fetching/brewery-likes/useGetBreweryPostLikeCount';
|
||||
import sendBreweryPostLikeRequest from '@/requests/sendBreweryPostLikeRequest';
|
||||
import { FC, useState } from 'react';
|
||||
import LikeButton from '../ui/LikeButton';
|
||||
|
||||
@@ -3,11 +3,12 @@ import { FaArrowUp } from 'react-icons/fa';
|
||||
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
|
||||
import useBeerPostComments from '@/hooks/useBeerPostComments';
|
||||
import useBreweryPostComments from '@/hooks/useBreweryPostComments';
|
||||
import useBeerPostComments from '@/hooks/data-fetching/beer-comments/useBeerPostComments';
|
||||
|
||||
import useBreweryPostComments from '@/hooks/data-fetching/brewery-comments/useBreweryPostComments';
|
||||
import NoCommentsCard from '../BeerById/NoCommentsCard';
|
||||
import LoadingComponent from '../BeerById/LoadingComponent';
|
||||
import CommentCardBody from '../BeerById/CommentCardBody';
|
||||
import CommentCardBody from '../BeerBreweryComments/CommentCardBody';
|
||||
|
||||
interface CommentsComponentProps {
|
||||
commentSectionRef: MutableRefObject<HTMLDivElement | null>;
|
||||
@@ -28,6 +29,11 @@ interface CommentsComponentProps {
|
||||
mutate: ReturnType<
|
||||
typeof useBeerPostComments | typeof useBreweryPostComments
|
||||
>['mutate'];
|
||||
handleDeleteRequest: (id: string) => Promise<void>;
|
||||
handleEditRequest: (
|
||||
id: string,
|
||||
data: { content: string; rating: number },
|
||||
) => Promise<void>;
|
||||
}
|
||||
|
||||
const CommentsComponent: FC<CommentsComponentProps> = ({
|
||||
@@ -39,6 +45,8 @@ const CommentsComponent: FC<CommentsComponentProps> = ({
|
||||
setSize,
|
||||
size,
|
||||
mutate,
|
||||
handleDeleteRequest,
|
||||
handleEditRequest,
|
||||
}) => {
|
||||
const { ref: penultimateCommentRef } = useInView({
|
||||
/**
|
||||
@@ -67,7 +75,12 @@ const CommentsComponent: FC<CommentsComponentProps> = ({
|
||||
ref={isPenultimateComment ? penultimateCommentRef : undefined}
|
||||
key={comment.id}
|
||||
>
|
||||
<CommentCardBody comment={comment} mutate={mutate} />
|
||||
<CommentCardBody
|
||||
comment={comment}
|
||||
mutate={mutate}
|
||||
handleDeleteRequest={handleDeleteRequest}
|
||||
handleEditRequest={handleEditRequest}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import useMediaQuery from '@/hooks/useMediaQuery';
|
||||
import useNavbar from '@/hooks/useNavbar';
|
||||
import useMediaQuery from '@/hooks/utilities/useMediaQuery';
|
||||
import useNavbar from '@/hooks/utilities/useNavbar';
|
||||
import useTheme from '@/hooks/utilities/useTheme';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { FC } from 'react';
|
||||
import { MdDarkMode, MdLightMode } from 'react-icons/md';
|
||||
import { GiHamburgerMenu } from 'react-icons/gi';
|
||||
import useTheme from '@/hooks/useTheme';
|
||||
|
||||
const DesktopLinks: FC = () => {
|
||||
const { pages, currentURL } = useNavbar();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import useUser from '@/hooks/useUser';
|
||||
import useUser from '@/hooks/auth/useUser';
|
||||
import GetUserSchema from '@/services/User/schema/GetUserSchema';
|
||||
import { createContext } from 'react';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -3,9 +3,12 @@ import { useRouter } from 'next/router';
|
||||
import { useContext } from 'react';
|
||||
|
||||
/**
|
||||
* Custom React hook that redirects the user to the home page if they are logged in. This
|
||||
* hook is used to prevent logged in users from accessing the login and signup pages. Must
|
||||
* be used under the UserContext provider.
|
||||
* Custom React hook that redirects the user to the home page if they are logged in.
|
||||
*
|
||||
* This hook is used to prevent logged in users from accessing the login and signup pages
|
||||
* by redirecting them to the home page.
|
||||
*
|
||||
* This hook should only be used in a component that is under the UserContext provider.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
@@ -5,11 +5,13 @@ import useSWR from 'swr';
|
||||
/**
|
||||
* A custom React hook that fetches the current user's data from the server.
|
||||
*
|
||||
* @returns An object containing the current user's data, a boolean indicating if the
|
||||
* request is currently loading, and an error object if an error occurred during the
|
||||
* request.
|
||||
* @throws When the user is not logged in, the server returns an error status code, or if
|
||||
* the response data fails to validate against the expected schema.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `user`: The current user's data.
|
||||
* - `isLoading`: A boolean indicating whether the request is still in progress.
|
||||
* - `error`: An error object if the user is not logged in, if the response data fails to
|
||||
* validate against the expected schema, or if the server returns an error.
|
||||
* - `mutate`: A function that can be used to mutate the current user's data.
|
||||
*/
|
||||
const useUser = () => {
|
||||
const {
|
||||
@@ -16,22 +16,31 @@ interface UseBeerPostCommentsProps {
|
||||
* @param props.pageNum - The page number of the comments to fetch.
|
||||
* @param props.id - The ID of the beer post to fetch comments for.
|
||||
* @param props.pageSize - The number of comments to fetch per page.
|
||||
* @returns An object containing the fetched comments, the total number of comment pages,
|
||||
* a boolean indicating if the request is currently loading, and a function to mutate
|
||||
* the data.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `comments`: The comments for the beer post.
|
||||
* - `isLoading`: A boolean indicating whether the comments are being fetched.
|
||||
* - `error`: The error that occurred while fetching the comments.
|
||||
* - `mutate`: A function to mutate the comments.
|
||||
* - `size`: The number of pages of comments that have been fetched.
|
||||
* - `setSize`: A function to set the number of pages of comments that have been fetched.
|
||||
* - `isLoadingMore`: A boolean indicating whether more comments are being fetched.
|
||||
* - `isAtEnd`: A boolean indicating whether all comments have been fetched.
|
||||
* - `pageCount`: The total number of pages of comments.
|
||||
*/
|
||||
const useBeerPostComments = ({ id, pageSize }: UseBeerPostCommentsProps) => {
|
||||
const fetcher = async (url: string) => {
|
||||
const response = await fetch(url);
|
||||
|
||||
const json = await response.json();
|
||||
const count = response.headers.get('X-Total-Count');
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
if (!parsed.success) {
|
||||
throw new Error(parsed.error.message);
|
||||
}
|
||||
const parsedPayload = z.array(CommentQueryResult).safeParse(parsed.data.payload);
|
||||
|
||||
const parsedPayload = z.array(CommentQueryResult).safeParse(parsed.data.payload);
|
||||
if (!parsedPayload.success) {
|
||||
throw new Error(parsedPayload.error.message);
|
||||
}
|
||||
@@ -6,8 +6,12 @@ import useSWR from 'swr';
|
||||
* Custom hook to fetch the like count for a beer post from the server.
|
||||
*
|
||||
* @param beerPostId - The ID of the beer post to fetch the like count for.
|
||||
* @returns An object with the current like count, as well as metadata about the current
|
||||
* state of the request.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `error`: The error that occurred while fetching the like count.
|
||||
* - `isLoading`: A boolean indicating whether the like count is being fetched.
|
||||
* - `mutate`: A function to mutate the like count.
|
||||
* - `likeCount`: The like count for the beer post.
|
||||
*/
|
||||
|
||||
const useGetBeerPostLikeCount = (beerPostId: string) => {
|
||||
@@ -9,22 +9,23 @@ import { z } from 'zod';
|
||||
* data from the server.
|
||||
*
|
||||
* @param beerPostId The ID of the beer post to check for likes.
|
||||
* @returns An object containing a boolean indicating if the user has liked the beer post,
|
||||
* an error object if an error occurred during the request, and a boolean indicating if
|
||||
* the request is currently loading.
|
||||
* @throws When the user is not logged in, the server returns an error status code, or if
|
||||
* the response data fails to validate against the expected schema.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `error`: The error that occurred while fetching the data.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
* - `mutate`: A function to mutate the data.
|
||||
* - `isLiked`: A boolean indicating whether the current user has liked the beer post.
|
||||
*/
|
||||
const useCheckIfUserLikesBeerPost = (beerPostId: string) => {
|
||||
const { user } = useContext(UserContext);
|
||||
const { data, error, isLoading, mutate } = useSWR(
|
||||
`/api/beers/${beerPostId}/like/is-liked`,
|
||||
async () => {
|
||||
async (url) => {
|
||||
if (!user) {
|
||||
throw new Error('User is not logged in.');
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/beers/${beerPostId}/like/is-liked`);
|
||||
const response = await fetch(url);
|
||||
const json = await response.json();
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
@@ -5,9 +5,11 @@ import { z } from 'zod';
|
||||
* A custom React hook that searches for beer posts that match a given query string.
|
||||
*
|
||||
* @param query The search query string to match beer posts against.
|
||||
* @returns An object containing an array of search results matching the query, an error
|
||||
* object if an error occurred during the search, and a boolean indicating if the
|
||||
* request is currently loading.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `searchResults`: The beer posts that match the search query.
|
||||
* - `searchError`: The error that occurred while fetching the data.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
*/
|
||||
const useBeerPostSearch = (query: string | undefined) => {
|
||||
const { data, isLoading, error } = useSWR(
|
||||
@@ -8,7 +8,16 @@ import { z } from 'zod';
|
||||
*
|
||||
* @param options The options to use when fetching beer posts.
|
||||
* @param options.pageSize The number of beer posts to fetch per page.
|
||||
* @returns An object containing the beer posts, page count, and loading state.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `beerPosts`: The beer posts fetched from the API.
|
||||
* - `error`: The error that occurred while fetching the data.
|
||||
* - `isAtEnd`: A boolean indicating whether all data has been fetched.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
* - `isLoadingMore`: A boolean indicating whether more data is being fetched.
|
||||
* - `pageCount`: The total number of pages of data.
|
||||
* - `setSize`: A function to set the size of the data.
|
||||
* - `size`: The size of the data.
|
||||
*/
|
||||
const useBeerPosts = ({ pageSize }: { pageSize: number }) => {
|
||||
const fetcher = async (url: string) => {
|
||||
@@ -38,7 +47,7 @@ const useBeerPosts = ({ pageSize }: { pageSize: number }) => {
|
||||
};
|
||||
|
||||
const { data, error, isLoading, setSize, size } = useSWRInfinite(
|
||||
(index) => `/api/beers?pageNum=${index + 1}&pageSize=${pageSize}`,
|
||||
(index) => `/api/beers?page_num=${index + 1}&page_size=${pageSize}`,
|
||||
fetcher,
|
||||
);
|
||||
|
||||
@@ -49,13 +58,13 @@ const useBeerPosts = ({ pageSize }: { pageSize: number }) => {
|
||||
|
||||
return {
|
||||
beerPosts,
|
||||
pageCount,
|
||||
size,
|
||||
setSize,
|
||||
error: error as unknown,
|
||||
isAtEnd,
|
||||
isLoading,
|
||||
isLoadingMore,
|
||||
isAtEnd,
|
||||
error: error as unknown,
|
||||
pageCount,
|
||||
setSize,
|
||||
size,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,7 +14,16 @@ interface UseBeerPostsByBreweryParams {
|
||||
* @param options The options to use when fetching beer posts.
|
||||
* @param options.pageSize The number of beer posts to fetch per page.
|
||||
* @param options.breweryId The ID of the brewery to fetch beer posts for.
|
||||
* @returns An object containing the beer posts, page count, and loading state.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `beerPosts`: The beer posts fetched from the API.
|
||||
* - `error`: The error that occurred while fetching the data.
|
||||
* - `isAtEnd`: A boolean indicating whether all data has been fetched.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
* - `isLoadingMore`: A boolean indicating whether more data is being fetched.
|
||||
* - `pageCount`: The total number of pages of data.
|
||||
* - `setSize`: A function to set the size of the data.
|
||||
* - `size`: The size of the data.
|
||||
*/
|
||||
const UseBeerPostsByBrewery = ({ pageSize, breweryId }: UseBeerPostsByBreweryParams) => {
|
||||
const fetcher = async (url: string) => {
|
||||
@@ -15,28 +15,35 @@ interface UseBreweryPostCommentsProps {
|
||||
* @param props.pageNum - The page number of the comments to fetch.
|
||||
* @param props.id - The ID of the brewery post to fetch comments for.
|
||||
* @param props.pageSize - The number of comments to fetch per page.
|
||||
* @returns An object containing the fetched comments, the total number of comment pages,
|
||||
* a boolean indicating if the request is currently loading, and a function to mutate
|
||||
* the data.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `comments`: The comments fetched from the API.
|
||||
* - `error`: The error that occurred while fetching the data.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
* - `isLoadingMore`: A boolean indicating whether more data is being fetched.
|
||||
* - `isAtEnd`: A boolean indicating whether all data has been fetched.
|
||||
* - `mutate`: A function to mutate the data.
|
||||
* - `pageCount`: The total number of pages of data.
|
||||
* - `setSize`: A function to set the size of the data.
|
||||
* - `size`: The size of the data.
|
||||
*/
|
||||
const useBreweryPostComments = ({ id, pageSize }: UseBreweryPostCommentsProps) => {
|
||||
const fetcher = async (url: string) => {
|
||||
const response = await fetch(url);
|
||||
const json = await response.json();
|
||||
const count = response.headers.get('X-Total-Count');
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
if (!parsed.success) {
|
||||
throw new Error(parsed.error.message);
|
||||
}
|
||||
const parsedPayload = z.array(CommentQueryResult).safeParse(parsed.data.payload);
|
||||
|
||||
const parsedPayload = z.array(CommentQueryResult).safeParse(parsed.data.payload);
|
||||
if (!parsedPayload.success) {
|
||||
throw new Error(parsedPayload.error.message);
|
||||
}
|
||||
|
||||
const pageCount = Math.ceil(parseInt(count as string, 10) / pageSize);
|
||||
|
||||
return { comments: parsedPayload.data, pageCount };
|
||||
};
|
||||
|
||||
@@ -4,6 +4,18 @@ import { useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* A custom React hook that checks if the current user likes a given brewery post.
|
||||
*
|
||||
* @param breweryPostId - The ID of the brewery post to check.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `isLiked`: A boolean indicating whether the current user likes the brewery post.
|
||||
* - `error`: The error that occurred while fetching the data.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
* - `mutate`: A function to mutate the data.
|
||||
*/
|
||||
|
||||
const useCheckIfUserLikesBreweryPost = (breweryPostId: string) => {
|
||||
const { user } = useContext(UserContext);
|
||||
const { data, error, isLoading, mutate } = useSWR(
|
||||
@@ -15,8 +27,8 @@ const useCheckIfUserLikesBreweryPost = (breweryPostId: string) => {
|
||||
|
||||
const response = await fetch(`/api/breweries/${breweryPostId}/like/is-liked`);
|
||||
const json = await response.json();
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
if (!parsed.success) {
|
||||
throw new Error('Invalid API response.');
|
||||
}
|
||||
@@ -2,6 +2,17 @@ import APIResponseValidationSchema from '@/validation/APIResponseValidationSchem
|
||||
import useSWR from 'swr';
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* A custom React hook that fetches the number of likes a brewery post has.
|
||||
*
|
||||
* @param breweryPostId
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `likeCount`: The number of likes the brewery post has.
|
||||
* - `error`: The error that occurred while fetching the data.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
* - `mutate`: A function to mutate the data.
|
||||
*/
|
||||
const useGetBreweryPostLikeCount = (breweryPostId: string) => {
|
||||
const { error, mutate, data, isLoading } = useSWR(
|
||||
`/api/breweries/${breweryPostId}/like`,
|
||||
@@ -10,15 +21,12 @@ const useGetBreweryPostLikeCount = (breweryPostId: string) => {
|
||||
const json = await response.json();
|
||||
|
||||
const parsed = APIResponseValidationSchema.safeParse(json);
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new Error('Failed to parse API response');
|
||||
}
|
||||
|
||||
const parsedPayload = z
|
||||
.object({
|
||||
likeCount: z.number(),
|
||||
})
|
||||
.object({ likeCount: z.number() })
|
||||
.safeParse(parsed.data.payload);
|
||||
|
||||
if (!parsedPayload.success) {
|
||||
@@ -8,7 +8,16 @@ import { z } from 'zod';
|
||||
*
|
||||
* @param options The options to use when fetching brewery posts.
|
||||
* @param options.pageSize The number of brewery posts to fetch per page.
|
||||
* @returns An object containing the brewery posts, page count, and loading state.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `breweryPosts`: The brewery posts fetched from the API.
|
||||
* - `error`: The error that occurred while fetching the data.
|
||||
* - `isAtEnd`: A boolean indicating whether all data has been fetched.
|
||||
* - `isLoading`: A boolean indicating whether the data is being fetched.
|
||||
* - `isLoadingMore`: A boolean indicating whether more data is being fetched.
|
||||
* - `pageCount`: The total number of pages of data.
|
||||
* - `setSize`: A function to set the size of the data.
|
||||
* - `size`: The size of the data.
|
||||
*/
|
||||
const useBreweryPosts = ({ pageSize }: { pageSize: number }) => {
|
||||
const fetcher = async (url: string) => {
|
||||
@@ -31,14 +40,11 @@ const useBreweryPosts = ({ pageSize }: { pageSize: number }) => {
|
||||
}
|
||||
|
||||
const pageCount = Math.ceil(parseInt(count as string, 10) / pageSize);
|
||||
return {
|
||||
breweryPosts: parsedPayload.data,
|
||||
pageCount,
|
||||
};
|
||||
return { breweryPosts: parsedPayload.data, pageCount };
|
||||
};
|
||||
|
||||
const { data, error, isLoading, setSize, size } = useSWRInfinite(
|
||||
(index) => `/api/breweries?pageNum=${index + 1}&pageSize=${pageSize}`,
|
||||
(index) => `/api/breweries?page_num=${index + 1}&page_size=${pageSize}`,
|
||||
fetcher,
|
||||
);
|
||||
|
||||
@@ -4,8 +4,7 @@ import { useEffect, useState } from 'react';
|
||||
* A custom React Hook that retrieves and monitors the user's geolocation using the
|
||||
* browser's built-in `navigator.geolocation` API.
|
||||
*
|
||||
* @returns An object containing the user's geolocation information and any errors that
|
||||
* might occur. The object has the following properties:
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `coords` - The user's current geolocation coordinates, or null if the geolocation could
|
||||
* not be retrieved.
|
||||
@@ -11,7 +11,10 @@ interface Page {
|
||||
* A custom hook that returns the current URL and the pages to display in the navbar. It
|
||||
* uses the user context to determine whether the user is authenticated or not.
|
||||
*
|
||||
* @returns An object containing the current URL and the pages to display in the navbar.
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `currentURL`: The current URL.
|
||||
* - `pages`: The pages to display in the navbar.
|
||||
*/
|
||||
const useNavbar = () => {
|
||||
const router = useRouter();
|
||||
@@ -2,13 +2,18 @@ import { useState, useEffect } from 'react';
|
||||
import useMediaQuery from './useMediaQuery';
|
||||
|
||||
/**
|
||||
* A custom hook to manage the theme of the app. If a preferred theme is not set in
|
||||
* localStorage, it will use what the user's browser prefers as determined by the
|
||||
* prefers-color-scheme media query. If the user changes their preferred theme, it will be
|
||||
* saved in localStorage and used in subsequent visits.
|
||||
* A custom hook to manage the theme of the app.
|
||||
*
|
||||
* @returns ThemeState.theme - The current theme of the app.
|
||||
* @returns ThemeState.setTheme - A setter function to change the theme of the app.
|
||||
* If a preferred theme is not set in localStorage, it will use what the user's browser
|
||||
* prefers as determined by the prefers-color-scheme media query.
|
||||
*
|
||||
* If the user changes their preferred theme, it will be saved in localStorage and used in
|
||||
* subsequent visits.
|
||||
*
|
||||
* @returns An object with the following properties:
|
||||
*
|
||||
* - `theme`: The current theme of the app.
|
||||
* - `setTheme`: A function to set the theme of the app.
|
||||
*/
|
||||
const useTheme = () => {
|
||||
const [theme, setTheme] = useState<'light' | 'dark'>('light');
|
||||
@@ -2,12 +2,17 @@ import formatDistanceStrict from 'date-fns/formatDistanceStrict';
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
/**
|
||||
* Returns the time distance between the provided date and the current time, using the
|
||||
* `date-fns` `formatDistanceStrict` function. This hook ensures that the same result is
|
||||
* calculated on both the server and client, preventing hydration errors.
|
||||
* A custom hook to calculate the time distance between the provided date and the current
|
||||
* time.
|
||||
*
|
||||
* This hook uses the date-fns library to calculate the time distance.
|
||||
*
|
||||
* This hook ensures that the same result is calculated on both the server and client,
|
||||
* preventing hydration errors.
|
||||
*
|
||||
* @param createdAt The date to calculate the time distance from.
|
||||
* @returns The time distance between the provided date and the current time.
|
||||
* @see https://date-fns.org/v2.30.0/docs/formatDistanceStrict
|
||||
*/
|
||||
const useTimeDistance = (createdAt: Date) => {
|
||||
const [timeDistance, setTimeDistance] = useState('');
|
||||
@@ -1,5 +1,5 @@
|
||||
import UserContext from '@/contexts/userContext';
|
||||
import useUser from '@/hooks/useUser';
|
||||
|
||||
import '@/styles/globals.css';
|
||||
import type { AppProps } from 'next/app';
|
||||
import { useEffect } from 'react';
|
||||
@@ -10,6 +10,7 @@ import { Analytics } from '@vercel/analytics/react';
|
||||
import { Space_Grotesk } from 'next/font/google';
|
||||
import Head from 'next/head';
|
||||
import Layout from '@/components/ui/Layout';
|
||||
import useUser from '@/hooks/auth/useUser';
|
||||
|
||||
const spaceGrotesk = Space_Grotesk({
|
||||
subsets: ['latin'],
|
||||
|
||||
@@ -9,8 +9,8 @@ import { z } from 'zod';
|
||||
|
||||
interface GetBeerPostsRequest extends NextApiRequest {
|
||||
query: {
|
||||
pageNum: string;
|
||||
pageSize: string;
|
||||
page_num: string;
|
||||
page_size: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ const getBeerPosts = async (
|
||||
req: GetBeerPostsRequest,
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
) => {
|
||||
const pageNum = parseInt(req.query.pageNum, 10);
|
||||
const pageSize = parseInt(req.query.pageSize, 10);
|
||||
const pageNum = parseInt(req.query.page_num, 10);
|
||||
const pageSize = parseInt(req.query.page_size, 10);
|
||||
|
||||
const beerPosts = await getAllBeerPosts(pageNum, pageSize);
|
||||
const beerPostCount = await DBClient.instance.beerPost.count();
|
||||
@@ -42,8 +42,8 @@ const router = createRouter<
|
||||
router.get(
|
||||
validateRequest({
|
||||
querySchema: z.object({
|
||||
pageNum: z.string().regex(/^\d+$/),
|
||||
pageSize: z.string().regex(/^\d+$/),
|
||||
page_num: z.string().regex(/^\d+$/),
|
||||
page_size: z.string().regex(/^\d+$/),
|
||||
}),
|
||||
}),
|
||||
getBeerPosts,
|
||||
|
||||
@@ -9,8 +9,8 @@ import { z } from 'zod';
|
||||
|
||||
interface GetBreweryPostsRequest extends NextApiRequest {
|
||||
query: {
|
||||
pageNum: string;
|
||||
pageSize: string;
|
||||
page_num: string;
|
||||
page_size: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ const getBreweryPosts = async (
|
||||
req: GetBreweryPostsRequest,
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
) => {
|
||||
const pageNum = parseInt(req.query.pageNum, 10);
|
||||
const pageSize = parseInt(req.query.pageSize, 10);
|
||||
const pageNum = parseInt(req.query.page_num, 10);
|
||||
const pageSize = parseInt(req.query.page_size, 10);
|
||||
|
||||
const breweryPosts = await getAllBreweryPosts(pageNum, pageSize);
|
||||
const breweryPostCount = await DBClient.instance.breweryPost.count();
|
||||
@@ -42,8 +42,8 @@ const router = createRouter<
|
||||
router.get(
|
||||
validateRequest({
|
||||
querySchema: z.object({
|
||||
pageNum: z.string().regex(/^\d+$/),
|
||||
pageSize: z.string().regex(/^\d+$/),
|
||||
page_num: z.string().regex(/^\d+$/),
|
||||
page_size: z.string().regex(/^\d+$/),
|
||||
}),
|
||||
}),
|
||||
getBreweryPosts,
|
||||
|
||||
106
src/pages/api/brewery-comments/[id].ts
Normal file
106
src/pages/api/brewery-comments/[id].ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { UserExtendedNextApiRequest } from '@/config/auth/types';
|
||||
import getCurrentUser from '@/config/nextConnect/middleware/getCurrentUser';
|
||||
import validateRequest from '@/config/nextConnect/middleware/validateRequest';
|
||||
import NextConnectOptions from '@/config/nextConnect/NextConnectOptions';
|
||||
import ServerError from '@/config/util/ServerError';
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import CreateCommentValidationSchema from '@/services/types/CommentSchema/CreateCommentValidationSchema';
|
||||
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { createRouter, NextHandler } from 'next-connect';
|
||||
import { z } from 'zod';
|
||||
|
||||
interface DeleteCommentRequest extends UserExtendedNextApiRequest {
|
||||
query: { id: string };
|
||||
}
|
||||
|
||||
interface EditCommentRequest extends UserExtendedNextApiRequest {
|
||||
query: { id: string };
|
||||
body: z.infer<typeof CreateCommentValidationSchema>;
|
||||
}
|
||||
|
||||
const checkIfCommentOwner = async (
|
||||
req: DeleteCommentRequest | EditCommentRequest,
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
next: NextHandler,
|
||||
) => {
|
||||
const { id } = req.query;
|
||||
const user = req.user!;
|
||||
const comment = await DBClient.instance.breweryComment.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!comment) {
|
||||
throw new ServerError('Comment not found', 404);
|
||||
}
|
||||
|
||||
if (comment.postedById !== user.id) {
|
||||
throw new ServerError('You are not authorized to modify this comment', 403);
|
||||
}
|
||||
|
||||
await next();
|
||||
};
|
||||
|
||||
const editComment = async (
|
||||
req: EditCommentRequest,
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
) => {
|
||||
const { id } = req.query;
|
||||
|
||||
const updated = await DBClient.instance.breweryComment.update({
|
||||
where: { id },
|
||||
data: {
|
||||
content: req.body.content,
|
||||
rating: req.body.rating,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: 'Comment updated successfully',
|
||||
statusCode: 200,
|
||||
payload: updated,
|
||||
});
|
||||
};
|
||||
|
||||
const deleteComment = async (
|
||||
req: DeleteCommentRequest,
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
) => {
|
||||
const { id } = req.query;
|
||||
|
||||
await DBClient.instance.breweryComment.delete({ where: { id } });
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Comment deleted successfully',
|
||||
statusCode: 200,
|
||||
});
|
||||
};
|
||||
|
||||
const router = createRouter<
|
||||
DeleteCommentRequest,
|
||||
NextApiResponse<z.infer<typeof APIResponseValidationSchema>>
|
||||
>();
|
||||
|
||||
router
|
||||
.delete(
|
||||
validateRequest({ querySchema: z.object({ id: z.string().uuid() }) }),
|
||||
getCurrentUser,
|
||||
checkIfCommentOwner,
|
||||
deleteComment,
|
||||
)
|
||||
.put(
|
||||
validateRequest({
|
||||
querySchema: z.object({ id: z.string().uuid() }),
|
||||
bodySchema: CreateCommentValidationSchema,
|
||||
}),
|
||||
getCurrentUser,
|
||||
checkIfCommentOwner,
|
||||
editComment,
|
||||
);
|
||||
|
||||
const handler = router.handler(NextConnectOptions);
|
||||
export default handler;
|
||||
@@ -2,7 +2,7 @@ import { NextPage } from 'next';
|
||||
import Head from 'next/head';
|
||||
import React from 'react';
|
||||
|
||||
import withPageAuthRequired from '@/getServerSideProps/withPageAuthRequired';
|
||||
import withPageAuthRequired from '@/util/withPageAuthRequired';
|
||||
import getBeerPostById from '@/services/BeerPost/getBeerPostById';
|
||||
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
import EditBeerPostForm from '@/components/EditBeerPostForm';
|
||||
|
||||
@@ -16,7 +16,7 @@ import { z } from 'zod';
|
||||
|
||||
import 'react-responsive-carousel/lib/styles/carousel.min.css';
|
||||
import { Carousel } from 'react-responsive-carousel';
|
||||
import useMediaQuery from '@/hooks/useMediaQuery';
|
||||
import useMediaQuery from '@/hooks/utilities/useMediaQuery';
|
||||
import { Tab } from '@headlessui/react';
|
||||
|
||||
interface BeerPageProps {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import CreateBeerPostForm from '@/components/CreateBeerPostForm';
|
||||
import FormPageLayout from '@/components/ui/forms/FormPageLayout';
|
||||
|
||||
import withPageAuthRequired from '@/getServerSideProps/withPageAuthRequired';
|
||||
import withPageAuthRequired from '@/util/withPageAuthRequired';
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import getAllBreweryPosts from '@/services/BreweryPost/getAllBreweryPosts';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
|
||||
@@ -9,7 +9,7 @@ import { MutableRefObject, useContext, useRef } from 'react';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
import Spinner from '@/components/ui/Spinner';
|
||||
|
||||
import useBeerPosts from '@/hooks/useBeerPosts';
|
||||
import useBeerPosts from '@/hooks/data-fetching/beer-posts/useBeerPosts';
|
||||
import { FaArrowUp, FaPlus } from 'react-icons/fa';
|
||||
import LoadingCard from '@/components/ui/LoadingCard';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ChangeEvent, useEffect, useState } from 'react';
|
||||
import Spinner from '@/components/ui/Spinner';
|
||||
|
||||
import debounce from 'lodash/debounce';
|
||||
import useBeerPostSearch from '@/hooks/useBeerPostSearch';
|
||||
import useBeerPostSearch from '@/hooks/data-fetching/beer-posts/useBeerPostSearch';
|
||||
import FormLabel from '@/components/ui/forms/FormLabel';
|
||||
|
||||
const DEBOUNCE_DELAY = 300;
|
||||
|
||||
@@ -7,7 +7,7 @@ import Head from 'next/head';
|
||||
import Image from 'next/image';
|
||||
import 'react-responsive-carousel/lib/styles/carousel.min.css'; // requires a loader
|
||||
import { Carousel } from 'react-responsive-carousel';
|
||||
import useMediaQuery from '@/hooks/useMediaQuery';
|
||||
import useMediaQuery from '@/hooks/utilities/useMediaQuery';
|
||||
import { Tab } from '@headlessui/react';
|
||||
import BreweryInfoHeader from '@/components/BreweryById/BreweryInfoHeader';
|
||||
import BreweryPostMap from '@/components/BreweryById/BreweryPostMap';
|
||||
|
||||
@@ -2,7 +2,7 @@ import BreweryCard from '@/components/BreweryIndex/BreweryCard';
|
||||
import LoadingCard from '@/components/ui/LoadingCard';
|
||||
import Spinner from '@/components/ui/Spinner';
|
||||
import UserContext from '@/contexts/userContext';
|
||||
import useBreweryPosts from '@/hooks/useBreweryPosts';
|
||||
import useBreweryPosts from '@/hooks/data-fetching/brewery-posts/useBreweryPosts';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
import { NextPage } from 'next';
|
||||
import Head from 'next/head';
|
||||
|
||||
@@ -13,7 +13,7 @@ import DBClient from '@/prisma/DBClient';
|
||||
import LocationMarker from '@/components/ui/LocationMarker';
|
||||
import Link from 'next/link';
|
||||
import Head from 'next/head';
|
||||
import useGeolocation from '@/hooks/useGeolocation';
|
||||
import useGeolocation from '@/hooks/utilities/useGeolocation';
|
||||
|
||||
type MapStyles = Record<'light' | 'dark', `mapbox://styles/mapbox/${string}`>;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { FaUserCircle } from 'react-icons/fa';
|
||||
import Head from 'next/head';
|
||||
import Link from 'next/link';
|
||||
|
||||
import useRedirectWhenLoggedIn from '@/hooks/useRedirectIfLoggedIn';
|
||||
import useRedirectWhenLoggedIn from '@/hooks/auth/useRedirectIfLoggedIn';
|
||||
|
||||
const LoginPage: NextPage = () => {
|
||||
useRedirectWhenLoggedIn();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import RegisterUserForm from '@/components/RegisterUserForm';
|
||||
import FormPageLayout from '@/components/ui/forms/FormPageLayout';
|
||||
|
||||
import useRedirectWhenLoggedIn from '@/hooks/useRedirectIfLoggedIn';
|
||||
import useRedirectWhenLoggedIn from '@/hooks/auth/useRedirectIfLoggedIn';
|
||||
import { NextPage } from 'next';
|
||||
import Head from 'next/head';
|
||||
import { BiUser } from 'react-icons/bi';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import Spinner from '@/components/ui/Spinner';
|
||||
import withPageAuthRequired from '@/getServerSideProps/withPageAuthRequired';
|
||||
import withPageAuthRequired from '@/util/withPageAuthRequired';
|
||||
import UserContext from '@/contexts/userContext';
|
||||
|
||||
import { GetServerSideProps, NextPage } from 'next';
|
||||
import { useContext } from 'react';
|
||||
import useMediaQuery from '@/hooks/useMediaQuery';
|
||||
import useMediaQuery from '@/hooks/utilities/useMediaQuery';
|
||||
|
||||
const ProtectedPage: NextPage = () => {
|
||||
const { user, isLoading } = useContext(UserContext);
|
||||
|
||||
@@ -10,10 +10,8 @@ CREATE TABLE "User" (
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
"isAccountVerified" BOOLEAN NOT NULL DEFAULT false,
|
||||
"dateOfBirth" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BeerPost" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -26,10 +24,8 @@ CREATE TABLE "BeerPost" (
|
||||
"typeId" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
|
||||
CONSTRAINT "BeerPost_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BeerPostLike" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -37,10 +33,8 @@ CREATE TABLE "BeerPostLike" (
|
||||
"likedById" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
|
||||
CONSTRAINT "BeerPostLike_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BreweryPostLike" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -48,10 +42,8 @@ CREATE TABLE "BreweryPostLike" (
|
||||
"likedById" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
|
||||
CONSTRAINT "BreweryPostLike_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BeerComment" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -61,10 +53,8 @@ CREATE TABLE "BeerComment" (
|
||||
"content" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
|
||||
CONSTRAINT "BeerComment_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BeerType" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -72,23 +62,19 @@ CREATE TABLE "BeerType" (
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
"postedById" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "BeerType_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Location" (
|
||||
"id" TEXT NOT NULL,
|
||||
"city" TEXT NOT NULL,
|
||||
"stateOrProvince" TEXT,
|
||||
"country" TEXT,
|
||||
"coordinates" DOUBLE PRECISION[],
|
||||
"coordinates" DOUBLE PRECISION [],
|
||||
"address" TEXT NOT NULL,
|
||||
"postedById" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "Location_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BreweryPost" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -99,10 +85,8 @@ CREATE TABLE "BreweryPost" (
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
"postedById" TEXT NOT NULL,
|
||||
"dateEstablished" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "BreweryPost_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BreweryComment" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -112,10 +96,8 @@ CREATE TABLE "BreweryComment" (
|
||||
"content" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
|
||||
CONSTRAINT "BreweryComment_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BeerImage" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -126,10 +108,8 @@ CREATE TABLE "BeerImage" (
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3),
|
||||
"postedById" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "BeerImage_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BreweryImage" (
|
||||
"id" TEXT NOT NULL,
|
||||
@@ -140,72 +120,68 @@ CREATE TABLE "BreweryImage" (
|
||||
"caption" TEXT NOT NULL,
|
||||
"alt" TEXT NOT NULL,
|
||||
"postedById" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "BreweryImage_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "BreweryPost_locationId_key" ON "BreweryPost"("locationId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerPost" ADD CONSTRAINT "BeerPost_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerPost"
|
||||
ADD CONSTRAINT "BeerPost_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerPost" ADD CONSTRAINT "BeerPost_breweryId_fkey" FOREIGN KEY ("breweryId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerPost"
|
||||
ADD CONSTRAINT "BeerPost_breweryId_fkey" FOREIGN KEY ("breweryId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerPost" ADD CONSTRAINT "BeerPost_typeId_fkey" FOREIGN KEY ("typeId") REFERENCES "BeerType"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerPost"
|
||||
ADD CONSTRAINT "BeerPost_typeId_fkey" FOREIGN KEY ("typeId") REFERENCES "BeerType"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerPostLike" ADD CONSTRAINT "BeerPostLike_beerPostId_fkey" FOREIGN KEY ("beerPostId") REFERENCES "BeerPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerPostLike"
|
||||
ADD CONSTRAINT "BeerPostLike_beerPostId_fkey" FOREIGN KEY ("beerPostId") REFERENCES "BeerPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerPostLike" ADD CONSTRAINT "BeerPostLike_likedById_fkey" FOREIGN KEY ("likedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerPostLike"
|
||||
ADD CONSTRAINT "BeerPostLike_likedById_fkey" FOREIGN KEY ("likedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryPostLike" ADD CONSTRAINT "BreweryPostLike_breweryPostId_fkey" FOREIGN KEY ("breweryPostId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BreweryPostLike"
|
||||
ADD CONSTRAINT "BreweryPostLike_breweryPostId_fkey" FOREIGN KEY ("breweryPostId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryPostLike" ADD CONSTRAINT "BreweryPostLike_likedById_fkey" FOREIGN KEY ("likedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BreweryPostLike"
|
||||
ADD CONSTRAINT "BreweryPostLike_likedById_fkey" FOREIGN KEY ("likedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerComment" ADD CONSTRAINT "BeerComment_beerPostId_fkey" FOREIGN KEY ("beerPostId") REFERENCES "BeerPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerComment"
|
||||
ADD CONSTRAINT "BeerComment_beerPostId_fkey" FOREIGN KEY ("beerPostId") REFERENCES "BeerPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerComment" ADD CONSTRAINT "BeerComment_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerComment"
|
||||
ADD CONSTRAINT "BeerComment_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerType" ADD CONSTRAINT "BeerType_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerType"
|
||||
ADD CONSTRAINT "BeerType_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Location" ADD CONSTRAINT "Location_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "Location"
|
||||
ADD CONSTRAINT "Location_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryPost" ADD CONSTRAINT "BreweryPost_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BreweryPost"
|
||||
ADD CONSTRAINT "BreweryPost_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryPost" ADD CONSTRAINT "BreweryPost_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BreweryPost"
|
||||
ADD CONSTRAINT "BreweryPost_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryComment" ADD CONSTRAINT "BreweryComment_breweryPostId_fkey" FOREIGN KEY ("breweryPostId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BreweryComment"
|
||||
ADD CONSTRAINT "BreweryComment_breweryPostId_fkey" FOREIGN KEY ("breweryPostId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryComment" ADD CONSTRAINT "BreweryComment_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BreweryComment"
|
||||
ADD CONSTRAINT "BreweryComment_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerImage" ADD CONSTRAINT "BeerImage_beerPostId_fkey" FOREIGN KEY ("beerPostId") REFERENCES "BeerPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerImage"
|
||||
ADD CONSTRAINT "BeerImage_beerPostId_fkey" FOREIGN KEY ("beerPostId") REFERENCES "BeerPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BeerImage" ADD CONSTRAINT "BeerImage_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BeerImage"
|
||||
ADD CONSTRAINT "BeerImage_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryImage" ADD CONSTRAINT "BreweryImage_breweryPostId_fkey" FOREIGN KEY ("breweryPostId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "BreweryImage"
|
||||
ADD CONSTRAINT "BreweryImage_breweryPostId_fkey" FOREIGN KEY ("breweryPostId") REFERENCES "BreweryPost"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BreweryImage" ADD CONSTRAINT "BreweryImage_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE "BreweryImage"
|
||||
ADD CONSTRAINT "BreweryImage_postedById_fkey" FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -6,10 +6,9 @@ generator client {
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
|
||||
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
|
||||
shadowDatabaseUrl = env("POSTGRES_URL_NON_POOLING") // used for migrations
|
||||
provider = "postgresql"
|
||||
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
|
||||
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
|
||||
}
|
||||
|
||||
model User {
|
||||
|
||||
@@ -2,15 +2,26 @@ import DBClient from '../../DBClient';
|
||||
|
||||
const cleanDatabase = async () => {
|
||||
const prisma = DBClient.instance;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "User" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerPost" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerType" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BreweryPost" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerComment" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BreweryComment" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerPostLike" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BeerImage" CASCADE`;
|
||||
await prisma.$executeRaw`TRUNCATE TABLE "BreweryImage" CASCADE`;
|
||||
|
||||
/**
|
||||
* Truncate all tables in the database.
|
||||
*
|
||||
* Declares a cursor called statements that contains all table names in the public
|
||||
* schema then loops through each table and truncates it.
|
||||
*/
|
||||
await prisma.$executeRaw`
|
||||
DO $$
|
||||
DECLARE
|
||||
statements CURSOR FOR
|
||||
SELECT tablename FROM pg_tables
|
||||
WHERE schemaname = 'public';
|
||||
BEGIN
|
||||
FOR statement IN statements LOOP
|
||||
EXECUTE 'TRUNCATE TABLE ' || quote_ident(statement.tablename) || ' CASCADE;';
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
`;
|
||||
|
||||
await prisma.$disconnect();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user