-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
589 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/spacecat-shared-data-access/src/dto/site-candidate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Data transfer object for Site Candidate. | ||
*/ | ||
export const SiteCandidateDto = { | ||
/** | ||
* Converts a Site Candidate object into a DynamoDB item. | ||
* @param {Readonly<SiteCandidate>} siteCandidate - Site Candidate object. | ||
* @returns {{baseURL, status, createdAt, updatedAt, updatedBy}} | ||
*/ | ||
toDynamoItem: (siteCandidate) => ({ | ||
baseURL: siteCandidate.getBaseURL(), | ||
status: siteCandidate.getStatus(), | ||
createdAt: siteCandidate.getCreatedAt(), | ||
updatedAt: siteCandidate.getUpdatedAt(), | ||
updatedBy: siteCandidate.getUpdatedBy(), | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/spacecat-shared-data-access/src/models/site-candidate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { hasText, isValidUrl } from '@adobe/spacecat-shared-utils'; | ||
|
||
import { Base } from './base.js'; | ||
|
||
export const DEFAULT_UPDATED_BY = 'spacecat'; | ||
|
||
export const SITE_CANDIDATE_STATUS = { | ||
DISCOVERED: 'DISCOVERED', // site candidate is discovered | ||
PENDING: 'PENDING', // site candidate notification sent and waiting for human input | ||
IGNORED: 'IGNORED', // site candidate discarded: not to be added to star catalogue | ||
APPROVED: 'APPROVED', // site candidate is added to star catalogue | ||
}; | ||
|
||
/** | ||
* Creates a new Site Candidate. | ||
* | ||
* @param {object} data - site candidate data | ||
* @returns {Readonly<SiteCandidate>} new site candidate | ||
*/ | ||
const SiteCandidate = (data = {}) => { | ||
const self = Base(data); | ||
delete self.id; // no id property used in SiteCandidate modal | ||
|
||
self.getBaseURL = () => self.state.baseURL; | ||
self.getStatus = () => self.state.status; | ||
self.getUpdatedBy = () => self.state.updatedBy; | ||
|
||
self.setStatus = (status, updatedBy = DEFAULT_UPDATED_BY) => { | ||
self.state.status = status; | ||
self.state.updatedBy = updatedBy; | ||
self.touch(); | ||
return self; | ||
}; | ||
|
||
return Object.freeze(self); | ||
}; | ||
|
||
/** | ||
* Creates a new Site Candidate. | ||
* | ||
* @param {object} data - site candidate data | ||
* @returns {Readonly<SiteCandidate>} new site candidate | ||
*/ | ||
export const createSiteCandidate = (data) => { | ||
const newState = { ...data }; | ||
|
||
if (!isValidUrl(newState.baseURL)) { | ||
throw new Error('Base URL must be a valid URL'); | ||
} | ||
|
||
if (!hasText(newState.updatedBy)) { | ||
newState.updatedBy = DEFAULT_UPDATED_BY; | ||
} | ||
|
||
return SiteCandidate(newState); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.